Trigger for field update in Salesforce

The below Apex code is used to update a field(Comments__c) in Member__c Object,

where Marital__Status and Comments__c are fields n Member__c object.

Sample Code:

trigger commentsUpdate on Member__c (before Insert,before update) 

     for(Member__c member : Trigger.new)  
     {      
         if(member.Marital_Status__c != '')    
         {      
             member.Comments__c = member.Marital_Status__c;    
         }       
         else   
         {      
             member.Comments__c = 'No comments';    
         }       
     }  
}


Cheers!!!

1 comment: