You need to sign in to do that
Don't have an account?
Charni Wiggins
Trigger count related records (via lookup) on Contact to update Account
I am trying to write a trigger on Account that is essentially a rollup of related records on the Contact level. Not the most confident with apex so just looking for some guidance..
I have created it from the Event Reg object and have a for soql loop to get all Event Reg records, including the Contact and Contacts AccountId, but am stuck at what to do now.
Any help would be much appreciated!
Hi Chami,
I have updated the total number of contacts in "Total_Contact__c" field of account. U can replace your appropriate field there(in Line no 19).
I hope it helps you.
Kindly let me know if it helps you and please mark as Best Answer.
Thanks and Regards,
Biswojeet
You can go with this code which is with best practice and optimised So try it. Here 'Number_of_Contacts__c' is a custom field in Account object of number type which contains the total number of related contacts . I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi