function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Batch Apex to sum Amount on custom field an update on another Custom Field..


i have 1time donation field on Transaction obj,This should be sumed up and update the field total amount on contact.
i have  a lookup on transaction to contact. how to write  batch apex fr this?


If i understood it correctly you want rollup on contact of 1time donation field of transaction custom object. there are three solutions to it.
1. Either you change the relation between both object from lookup to Master detail and create a Rollup summary field.(if lookup is not mandatory.)
2. If you want real time update then you should write a trigger on Transaction object that every time a transaction record inserted or update it calulate the amount and update it on contact.
3. if your org is big and you have flexibility to update data after a specific time. then only you should write apex batch. 

below link might help you write batch apex.