Display Date/Time Based On Lookup User.
VF Page:
<apex:page standardcontroller="Contact" extensions="RelatedController" showHeader="false">
<apex:form >
<apex:actionRegion >
<apex:pageBlock id="accinfo">
<apex:pageBlockSection title="Account Information">
<apex:inputField value="{!contact.AccountId}" id="abc">
<apex:actionSupport event="onchange" action="{!currentDatePopup}" rerender="accinfo,abc" />
</apex:inputField>
<apex:outputText value="{!currentDatetime }" label="Current Date/time" />
<apex:inputField value="{!contact.Look__c}" id="abc1">
<apex:actionSupport event="onchange" action="{!currentDatePopup1}" rerender="accinfo,abc1" />
</apex:inputField>
<apex:outputText value="{!currentDatetime1 }" label="Current "/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:actionRegion>
</apex:form>
</apex:page>
Apex Class:
public with sharing class RelatedController
{
private ApexPages.StandardController stdCtrl;
public Contact con;
public datetime currentDatetime{get;set;}
public datetime currentDatetime1{get;set;}
public void currentDatePopup()
{
currentDatetime = System.now();
}
public void currentDatePopup1()
{
currentDatetime1 = System.now();
}
public RelatedController(ApexPages.StandardController std)
{
stdCtrl=std;
}
public void AccountPopulated()
{
Contact cont=(Contact) stdCtrl.getRecord();
try{
if(cont.account!= null)
cont.Account=[select AccountNumber,CurrentDate__c,Lookuptest__c,DateTime__c from Account where id=:cont.AccountId ];
}
catch(exception e){}
}
}
actionFunction : provides support for invoking controller action methods directly from JavaScript code using an AJAXrequest Example : <!-- Page: --> <apex:page controller="exampleCon"> <apex:form> <!-- Define the JavaScript function sayHello--> <apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out" status="myStatus"/> </apex:form> <apex:outputPanel id="out"> <apex:outputText value="Hello "/> <apex:actionStatus startText="requesting..." id="myStatus"> <apex:facet name="stop">{!username}</apex:facet> </apex:actionStatus> </apex:outputPanel> <!-- Call the sayHello JavaScript function using a script element--> <script>window.setTimeout(sayHello,2000)</script> <p><apex:outputText value="Clicked? {!state}" id="showstate" /></p> <!-- Add the onclick event listener to a panel. When clicked, the panel triggers the methodOneInJavascript actionFunction with a param --> <apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn"> Click Me </apex:outputPanel> <apex:form> <apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="showstate"> <apex:param name="firstParam" assignTo="{!state}" value="" /> </apex:actionFunction> </apex:form> </apex:page> /*** Controller ***/ public class exampleCon { String uname; public String getUsername() { return uname; } public PageReference sayHello() { uname = UserInfo.getName(); return null; } public void setState(String n) { state = n; } public String getState() { return state; } public PageReference methodOne() { return null; } private String state = 'no'; }<!-- Page: --> <apex:page controller="exampleCon"> <apex:form> <apex:outputpanel id="counter"> <apex:outputText value="Click Me!: {!count}"/> <apex:actionSupport event="onclick" action="{!incrementCounter}" rerender="counter" status="counterStatus"/> </apex:outputpanel> <apex:actionStatus id="counterStatus" startText=" (incrementing...)" stopText=" (done)"/> </apex:form> </apex:page> /*** Controller: ***/ public class exampleCon { Integer count = 0; public PageReference incrementCounter() { count++; return null; } public Integer getCount() { return count; } }<!-- Page --> <apex:page controller="exampleCon"> <apex:form> <apex:outputText value="Watch this counter: {!count}" id="counter"/> <apex:actionPoller action="{!incrementCounter}" rerender="counter" interval="15"/> </apex:form> </apex:page> /*** Controller: ***/ public class exampleCon { Integer count = 0; public PageReference incrementCounter() { count++; return null; }