Orphaned CronJobDetail records breaking Scheduled Jobs in Salesforce Summer ’17

Matt/ July 20, 2017/ Salesforce

For the second year in a row, we’re lucky to be among the first to discover a problem with the summer release of Salesforce, and have that problem become a known issue. Last year LightningLockerServices Critical Update.

What’s the problem?

I’m witnessing an issue in a sandbox we recently refreshed. We’re running a vendor product on top of Salesforce (this issue will still affect you, even if you’re not running the same app). Within the app’s admin panel, I’m trying to start something called ‘Scheduler’, which corresponds to a Salesforce scheduled apex job. However, this job never starts, and no error is gets displayed.

So, something doesn’t work, and we’ve got no leads to follow. That’s where the fun begins!

What we’ve discovered is an issue with Summer ’17 when it comes to refreshing a sandbox copy of an org (this is now a known issue). Specifically, a sandbox refresh no longer copies over CronTrigger rows for scheduled apex jobs, but associated CronJobDetail rows still get copied. Therefore, when you refresh a sandbox, if you have configured scheduled apex jobs in your production org, you’re going to end up with orphaned CronJobDetail rows.

How do all these things work together?

Ok, let’s break this down a bit. In Salesforce, scheduled Apex jobs are stored as CronTrigger records. You can see a list of your scheduled apex jobs in Developer Console by running the following query:

SELECT ID, CronExpression, CronJobDetail.Name, CronJobDetailId, EndTime, NextFireTime, PreviousFireTime, StartTime, State, TimesTriggered FROM CronTrigger

One of the columns returned is CronJobDetailId. This is a reference to the CronJobDetail sObject. CronJobDetail records describe the CronTrigger records. You can query these records in Developer Console to see those details as well:

SELECT Id, Name, JobType FROM CronJobDetail

Because of this issue, we have CronJobDetail records that have been copied over, but the parent CronTrigger records haven’t been.  The Name field on CronJobDetail must be unique, and since we’re trying to create two records with the same Name, the whole process fails.

How do we solve this?

Clients cannot do anything to rectify this. It’s up to Salesforce to solve this issue, and the issue is currently under their review. Until then, you must open a case with Salesforce support and ask them to delete the orphaned CronJobDetail rows.

Share this Post

About Matt

Matt is a seasoned Salesforce Developer / Architect, with implementations of Sales Cloud, Service Cloud, CPQ, Experience Cloud, and numerous innovative applications built upon the Force.com platform. He started coding in grade 8 and has won awards ranging from international scholarships to internal corporate leadership awards. He is 37x Certified on the platform, including Platform Developer II, B2B Solution Architect and B2C Solution Architect.