Posts

Showing posts from February, 2018

Bulkify Trigger Example

Trigger : Update Account Total_Amount field  by sum of all its Contact Money field (Roll up summary trigger) For this following steps as follow: 1. Create custom field Create a custom field on Account named :  Total Money Create a custom field on Contact named :  Money 2. Create a Apex Class (Handler class for Trigger) named :  AccountTotalMoneyHandler public class AccountTotalMoneyHandler{          public static void onAfterInsert(List<Contact> lstNewContacts){         Set<Id> setAccountIds= new Set<Id>();         for(Contact con : lstNewContacts){             if(con.AccountId != NULL){                 setAccountIds.add(con.AccountId);             }         }         if(setAccountIds.size() > 0){             populateMoneyOnAccount(setAccountIds);         }     }        public static void onAfterUpdate(List<Contact> lstNewContacts,Map<Id,Contact> mapOldContact){         Set<Id> setAccountIds= new Set<