Sunday, 30 October 2011

Bulikfy Apex Code / Trigger


Bulkifying Apex code refers to the concept of making sure the code properly handles more than one record at a time.  If a batch of records (via the webservices call) invokes the same Apex code, all of those records need to be processed as a bulk, in order to write scalable code and avoid hitting governor limits.
eg.
trigger accountTestTrggr on Account (before insert, before update) {

   List<String> accountNames = new List<String>() {
 
   //Loop through all records in the Trigger.new collection
   for(Account a: Trigger.new){
      //Concatenate the Name and billingState into the Description field
      a.Description = a.Name + ':' + a.BillingState
   }
   
}

No comments:

Post a Comment