[SalesForce] How to change or set the Crontrigger OwnerId

Is there any way to change or set the crontrigger ownerId? I started an Apex Job in a Post Install Script and the ownerId is the installed package. I need change it or abort the job and start it again with the System Administratior id.

Thanks, Airton.

Best Answer

The only way to set the OwnerId is to be logged in as that user.

Per the CronTrigger Docs only query is supported and you cannot use DML for this object.

The simplest way to do this is to first log in as the right user and just delete the job from setup (setup->monitor->scheduled jobs), and then reschedule (setup->develop->apex classes, click 'Schedule Apex').

You could do this with apex as well if you have the scheduled job id

Id jobId = '00000000000000';
String jobName = 'JobName';
String cronString = '0 0 0 3 9 ? 2022';
system.abortJob(jobId);
system.schedule(jobName, cronString, new SchedulableClass());