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
Praveen JhaPraveen Jha 

Apex Batch Script to Opt All Users

I have  2 new fields on a User record in sandbox: -          
Notify_me_of_alerts__c -          
Notify_me_of_releases__c  
Once this is moved to Production, I will want to ensure that all users are opted in (i.e. the values are set to TRUE).   There are triggers associated with these two fields that if changed will add and remove the users from Public Groups. The user may exist in more than one Public Group, depending on the related Products for the Assets of the User’s Contact Account.  
  If I have a batch job that goes through all the Users and updates their records to set the two flags to TRUE, this will kick off the Trigger and populate the groups. Is there a danger of overloading Salesforce if this happens?   We have around 1000 users, so this would fire off 1000 instances of the trigger.     If this is likely to be an issue. Please suggest me on this.
Best Answer chosen by Praveen Jha
Himanshu ParasharHimanshu Parashar
Hi Praveen,

It will not fire 1000 instances of trigger as it is running in batch. I think you might already know that Batch process records in 200 chunk and after that it reset the limits except you haven't mentioned batch size as 1. so if you have 1000 users it will only fire 5 instance not 1000 which I think should not be an issue.

Does it makes sense ?

Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer.

All Answers

Himanshu ParasharHimanshu Parashar
Hi Praveen,

It will not fire 1000 instances of trigger as it is running in batch. I think you might already know that Batch process records in 200 chunk and after that it reset the limits except you haven't mentioned batch size as 1. so if you have 1000 users it will only fire 5 instance not 1000 which I think should not be an issue.

Does it makes sense ?

Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S. If my answer helps you to solve your problem please mark it as best answer.
This was selected as the best answer
Himanshu ParasharHimanshu Parashar
Hi Praveen,

Salesforce provide very quality material to learn apex. you can start learning using their workbook

http://www.salesforce.com/us/developer/docs/apex_workbook/apex_workbook.pdf