Monday, August 6, 2018

How to add months to date field in salesforce using formula expression builder

If you want to add say 6 months to the date fields in salesforce,its not straightforward. Please see this example as to how to achieve it.

DATE( 
YEAR(start_date__c) + FLOOR( ( MONTH (start_date__c) + 6 - 1 ) / 12 ), 
MOD( MONTH (start_date__c) + 6- 1 + 
IF( DAY (start_date__c) > CASE( MOD( MONTH(start_date__c) +6- 1, 12 ) + 1, 
2, 28, 
4, 30, 
6, 30, 
9, 30, 
11, 30, 
31 ), 1, 0 ), 12 ) + 1, 
IF( DAY(start_date__c ) > CASE( MOD( MONTH(start_date__c ) +6 - 1, 12 ) + 1, 
2, 28, 
4, 30, 
6, 30, 
9, 30, 
11, 30, 
31 ), 
1, DAY(start_date__c ) 
)


Saturday, August 4, 2018

How to create Wrapper class in salesforce

public with sharing class testwrappercontroller {

    //createing a list for wrapper class object
    // always try to create list seperately outside
//    constructor and return it rseperately
//the key concept here is to create list and other variablesotuside
//the constructor.remeber the constructor does not always create all list variable
//variable get methods fire independently of constrcutor,where everthe the get set is defined for
//the variable,in the below case the wpl variable fires seperately
//when it sinvoed as {!wpl}
   public  List<wrapperclass> wpl {get
 
   {
 
    Account ac =[Select Id,name from Account limit 1];
    Contact co =[Select Id,name from Contact limit 1];
    wpl = new List<wrapperclass>();
    wpl.add(new wrapperclass(ac,co));
     return wpl;}
   
      set;}
 
    public void testwrappercontroller(){
    system.debug('hi');  
   
 

    }
   
 
   
    public class wrapperclass{
    public Account acc {get; set;}
    public Contact coo {get; set;}
    public  wrapperclass(Account a,Contact c){  
    acc =a;
    coo =c;  
   
     }
    }
   
   
}


<apex:page controller="testwrappercontroller" tabStyle="account">
  <apex:pageBlock >
  <apex:pageBlockSection title="Section" columns="2"/>
      <apex:pageBlockTable value="{!wpl}" var="cw"  >    
        <apex:column value="{!cw.acc.name}" rendered="true"/>
        <apex:column value="{!cw.coo.name}" rendered="true"/>
 
     
      </apex:pageBlockTable>
   
    </apex:pageBlock>
   
   
 
</apex:page>