You need to sign in to do that
Don't have an account?
Sammy Shk
How to run Batch apex to update Records based on count
Hello,
I'm new in apex and trying to run a batch apex. We have 2 objects, obj1 and obj2 and they have master detail relationship. We also have a End date time on obj1 and obj2 There could be multiple obj2 records related to obj1 , we want to run a batch that looks up all records in Obj2 which has more than 2 records related to obj1 and update the old ones with the End date time field from obj1. Is there any sample code that I can start with?
I'm new in apex and trying to run a batch apex. We have 2 objects, obj1 and obj2 and they have master detail relationship. We also have a End date time on obj1 and obj2 There could be multiple obj2 records related to obj1 , we want to run a batch that looks up all records in Obj2 which has more than 2 records related to obj1 and update the old ones with the End date time field from obj1. Is there any sample code that I can start with?
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
First you need to create a RollUp summary with count method in Obj1__c, that will count total Obj2__c associated.
After that you can use below code, ion this code Total_Obj2__c(Rollup Summary field)
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh