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
EalesieEalesie 

System.UnexpectedException thrown by System.Schedule method

I have a scheduled APEX class that is submitted via Apex using the System.Schedule method.  I am passing a String variable that is dynamically built as the schedule name and I have been randomly receiving an Unhandled Exception caused by: System.UnexpectedException: trigger must be associated with a job detail.

 

I have tried wrapping the calling code in try catch blocks but I am unable to trap this error.

 

After several hours of debugging, trying to replicate the error on demand I have tracked the issue down to the parameter being passed as the Schedule Name ending with a space.

 

Note: ensure you trim leading/ending spaces from Schedule names (and ensure the name does not exceed 60 characters) when submitting  schedule classes

 

Best Answer chosen by Admin (Salesforce Developers) 
EalesieEalesie

After several hours of debugging, trying to replicate the error on demand I have tracked the issue down to the parameter being passed as the Schedule Name ending with a space.

 

Note: ensure you trim leading/ending spaces from Schedule names (and ensure the name does not exceed 60 characters) when submitting  schedule classes