Skip to content

enreeco/sf-apex-execute-anonymous-batch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Execute Anonymous Batch

Author: Enrico Murru

Read details @ http://blog.enree.co/2017/08/salesforce-apex-execute-anonymous-batch.html

The ID_LIST global variable is of type List<ID> and contains all the IDs provided by the Batch's scope.

Remember to configure a named credential called EXECUTE_ANONYMOUS that points to your instance (and that is logged with a valid session ID).

Example of usage:

String script = 'List<Account> acList = [Select Id, Name From Account Where Id IN :ID_LIST];' 
				+'\nfor(Account acc : acList){'
				+'\n   acc.BillingCity = \'Gnite City\';'
				+'\n}'
				+'\n update acList;';

String query = 'Select Id From Account Where BillingCity != \'Gnite City\'';

Boolean sendEmailOnFinish = true;

ExecuteAnonymousBatch batch = new ExecuteAnonymousBatch(query, script, sendEmailOnFinish);
Database.executeBatch(batch, 100);

The job sends a completion email with all eventual errors on finish.

About

Salesforce Apex: Execute Anonymous Batch

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages