You need to sign in to do that
Don't have an account?
SFDC@Error
Trigger Not Updating
Hi All
I have created a trigger for sum of child field and update in parent like roll up summary through look up relationship.When i am creating new child record its working,but i am updating extisting child record its not working ...
I have created a trigger for sum of child field and update in parent like roll up summary through look up relationship.When i am creating new child record its working,but i am updating extisting child record its not working ...
trigger TotalSalesTrigger on Sales__c (after insert, after delete, after undelete, after update) { set<Id> invIdSet = new set<Id>(); if(trigger.isinsert || trigger.isUpdate || trigger.Isundelete){ for(Sales__c invItem: Trigger.new){ if(Trigger.isInsert || Trigger.isUndelete || (invItem.Sold_Price__c!= Trigger.oldMap.get(invItem.Id).Sold_Price__c|| invItem.Customer_Name__c!= Trigger.oldMap.get(invItem.Id).Customer_Name__c)) invIdSet.add(invItem.Customer_Name__c); } } if(trigger.isUpdate || trigger.isDelete) { for(Sales__c invItem: Trigger.old){ if(Trigger.isDelete || (invItem.Sold_Price__c!= Trigger.newMap.get(invItem.Id).Sold_Price__c|| invItem.Customer_Name__c!= Trigger.newMap.get(invItem.Id).Customer_Name__c)) invIdSet.add(invItem.Customer_Name__c); } } List<Contact> invList= [Select id,name,Total_Sale__c,(Select id,Sold_Price__c from Sales__r) from Contact Where ID IN: invIdSet]; for(Contact inv : invList){ inv.Total_Sale__c= 0; for(Sales__c invItem : inv.Sales__r) { inv.Total_Sale__c+= invItem.Sold_Price__c ; } } update invList;
You have developed good code.But in this code line no 6 and line no 12 there is the duplicate statement when the record will update.
maybe this duplication can create a problem for update the record.
Sol: remove the trigger.isUpdate one of line 4 or 10.because this will work same when the record will update.
Hope this will help you
Thanks Mukesh
https://appexchange.salesforce.com/appxListingDetail?listingId=a0N30000009i3UpEAI
Please check once below sample code :
Hope it helps you.
Let me know in case of any other assistance.
Thanks
Varaprasad
Thanks
Varaprasad
How can i create multiple child object when parent create .Multiple child object will be created based on lookup related child
Its created number of child record but not able to copy all record ....
I have facing this error when i am editing record .I am editing child record of contact.if one child then its working,if more than one child i am facing issue and its working in sandbox,but problem is coming from production.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger TotalSalesTrigger caused an unexpected exception, contact your administrator: TotalSalesTrigger: execution of AfterUpdate caused by: System.NullPointerException: Argument cannot be null.: Class.SampleRollupSummary.rollupContacts: line 31, column 1