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
@login.ax974@login.ax974 

Batch Apex - execute it from different user than the one submitted it

Hi,

 

Is it possible to assign a different contextual user to the batch apex than the one who has submitted it? If yes, can someone please provide an example.

 

Thanks much.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

No. Batch Apex will run as the current user. You should take this into consideration if you have validation rules, etc that might cause problems because of this. The only time you can alter the current running user is when running unit tests, which will not assist you in this case.

 

Edit: But it is running in system mode, which means that object level and field level security pose no threat. Just validations and triggers.

All Answers

sfdcfoxsfdcfox

No. Batch Apex will run as the current user. You should take this into consideration if you have validation rules, etc that might cause problems because of this. The only time you can alter the current running user is when running unit tests, which will not assist you in this case.

 

Edit: But it is running in system mode, which means that object level and field level security pose no threat. Just validations and triggers.

This was selected as the best answer
Anup JadhavAnup Jadhav

No, it is not possible to assign the batch to a different user at the moment.

 

- A