FavoriteMohammed asif Mamsury (ibirds software service) asked in #ApexSep 15, 2021, 6:13 AMRollup Summary Trigger for Lookup Relationshiptrigger RollUpSummaryTrigger on Contact (after insert, after update, after delete, after undelete) { Set<Id> accountId = new Set<Id>(); if(Trigger.isInsert && Trigger.isAfter) { for(Contact contactObj : Trigger.new){ accountId.add(contactObj.AccountId); } List<Account> accountList = [Select Id, Totel_Amount__c,(Select Id ,LastName , AccountId , Salary__c FROM Contacts) From Account Where Id IN: accountId]; List<Account> accountLists = New List<Account>(); for(Account accountObj : accountList){ double sumAmount = 0; for(Contact objcontact : accountObj.contacts){ sumAmount += objcontact.Salary__c; } accountObj.Totel_Amount__c = sumAmount; accountLists.add(accountObj); } if(accountLists.Size() > 0){ Update accountLists; } }}Show More2 answersSortSort by DateSort by Most HelpfulSort by DateLoad more comments...Sai Praveen Kumar Kakkirala (Salesforce)Sep 15, 2021, 6:36 AMHi Mohmmed,Can you let the community know what issue you are facing with the above code and what is the functionality you are trying to achieve. Thanks, Add a commentWrite an answer...BoldItalicUnderlineStrikethroughBulleted ListNumbered ListAdd linkCode blockInsert imageAttach filesLink URLCancelSave0/9000Reply
Sai Praveen Kumar Kakkirala (Salesforce)Sep 15, 2021, 6:36 AMHi Mohmmed,Can you let the community know what issue you are facing with the above code and what is the functionality you are trying to achieve. Thanks,