Tuesday 28 January 2014

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){}
 }
}










Radar Chart using Visualforce and Apex in Salesforce

Sample Code:

Visualforce page:


<apex:page sidebar="false" Controller="Sample" showHeader="true" id="pg">
<apex:chart height="750" width="800" legend="true" data="{!data}">
    <apex:legend position="left"/>
    <apex:axis type="Radial" position="radial">
        <apex:chartLabel />
    </apex:axis>
    <apex:radarSeries xField="memName" yField="tenthPercent" tips="true" opacity="0.4"/>
    <apex:radarSeries xField="memName" yField="twelthPercent" tips="true" opacity="0.4"/>
    <apex:radarSeries xField="memName" yField="age" tips="true" markerType="cross" strokeWidth="2" strokeColor="#f33" opacity="0.4"/>
</apex:chart>
</apex:page>

Apex Controller:

public class Sample {   

    public List<RadarData> data {get;set;}
    public sample() {
    data = new List<RadarData>();
        List<Member__c> memList = new List<Member__c>();
        memList = [SELECT Name, Age__c, X10th__c, X12th__c FROM Member__c];
        for(Member__c mem : memList) {
            data.add(new RadarData(mem.Name, mem.X10th__c, mem.X12th__c, mem.Age__c));
        }
    }
    public class RadarData {
        String memName {get;set;}
        Decimal tenthPercent {get;set;}
        Decimal twelthPercent {get;set;}
        Decimal age {get;set;}
        
        public RadarData(String memName, Decimal tenthPercent, Decimal twelthPercent, Decimal age) {
            this.memName = memName;
            this.tenthPercent = tenthPercent;
            this.twelthPercent = twelthPercent;
            this.Age = age;
        }
    }
}

Output:

How To: Call Apex code from a Custom Button

How do I call Apex code from a Custom Button?




The steps are as follows to add either a Detail or a List View  button (as illustrated below) to Standard or Custom Object. It’s well worth going through the topics and general reference guides I’ve linked in more detail. I’ve given some examples of my own, but there are also plenty of them in the help topics I’ve linked to if you need more examples.


Screen Shot 2013-07-16 at 09.13.00Screen Shot 2013-07-16 at 09.12.46
Steps to Create a Custom Button that runs Apex Code
  1. Create a Apex Extension Controller class as shown in the examples below.
  2. Create a Visualforce page, using the ‘standardController‘ and ‘extensions‘ attributes on apex:page
  3. Create a Custom Button using the Visualforce page as its Content Source
  4. Add the Custom Button to the appropriate Layout of the object
  5. Use either the ‘action‘ attribute (see warning below) or apex:commandButton‘s on your page to invoke Apex logic.

Detail Page Custom Button Template
Example page and class using apex:commandButton to invoke the logic.
1
2
3
4
5
<apex:page standardController="Test__c" extensions="DetailButtonController">
    <apex:form >
        <apex:commandButton value="Do something" action="{!doSomething}"/>
    </apex:form>
</apex:page>
Apex controller code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public with sharing class DetailButtonController
{
    private ApexPages.StandardController standardController;
    public DetailButtonController(ApexPages.StandardController standardController)
    {
        this.standardController = standardController;
    }
    public PageReference doSomething()
    {
        // Apex code for handling record from a Detail page goes here
        Id recordId = standardController.getId();
        Test__c record = (Test__c) standardController.getRecord();
        return null;
    }
}
Or to have your Apex logic run as soon as the user presses the Custom Button use the action attribute.
1
2
<apex:page standardController="Test__c" extensions="DetailButtonController"
           action="{!doSomething}">
To add the Custom Button should look something like this…
Screen Shot 2013-07-16 at 07.43.22
List View Custom Button Template
Example page and class, using apex:commandButton to invoke the logic.
1
2
3
4
5
6
<apex:page standardController="Test__c" extensions="ListButtonController"
           recordSetVar="TestRecords">
    <apex:form >
        <apex:commandButton value="Do something" action="{!doSomething}"/>
    </apex:form>
</apex:page>
Apex controller code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public with sharing class ListButtonController
{
    private ApexPages.StandardSetController standardSetController;
    public ListButtonController(ApexPages.StandardSetController standardSetController)
    {
        this.standardSetController = standardSetController;
    }
    public PageReference doSomething()
    {
        // Apex code for handling records from a List View goes here
        List<Test__c> listViewRecords =
            (List<Test__c>) standardSetController.getRecords();
        List<Test__c> selectedListViewRecords =
            (List<Test__c>) standardSetController.getSelected();
        Boolean hasMore = standardSetController.getHasNext();
        return null;
    }
}
Or to have your Apex logic run as soon as the user presses the Custom Button use the action attribute.
1
2
<apex:page standardController="Test__c" extensions="ListButtonController"
           action="{!doSomething}" recordSetVar="TestRecords">
To add the Custom Button should look something like this…

Screen Shot 2013-07-16 at 07.43.58