I am implementing apex scheduler, i wondering how can i change Run User As to some one else. Presently it is taking current User.

Thanks in advance.


You'll need to schedule the job as the appropriate user in terms of whoever is actually executing the code (whether it is via some sort of Visualforce UI or the user scheduling the Apex Job via the UI). The System.RunAs functionality only exists in unit tests.


  • 2
    In other words, you have to login as that user and schedule it. I usually make a Visualforce page so they don't have to be administrators necessarily.
    – sfdcfox
    Oct 16 '14 at 19:09
  • Hi @michael, i am using visualforce UI and displaying the user and selecting the user. but how can we include this user to cron job. Now it is taking logged in user as job owner
    – Sunny
    Oct 17 '14 at 3:52
  • Hi @sfdcfox, how can we pass the user after selecting in visualforce page
    – Sunny
    Oct 17 '14 at 6:11
  • 1
    I believe you'll need that user to visit the Visualforce page and click the button (or whatever mechanism you want to use that invokes the Apex code that schedules the job). You can alternatively have your users grant you login access and do it yourself, but you can't programmatically schedule a job as someone else via Apex. Oct 17 '14 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.