8

The question itself is relatively simple.

If I call System.schedule(String jobName, String cronExpression, Object schedulableClass), what is the maximum length for a scheduled jobname parameter?

The answer wasn't immediately apparent in the System class docs.

As an aside, I'm asking because I've run into a scenario where I need to go to extra lengths to ensure the scheduled job name is unique.

The current code I have takes into account the time when the job was scheduled. However, I've run into a scenario where a subscriber org has spun up all 50 Queueable jobs in one transaction. When each job runs it is trying to schedule another class to run. Depending on the exact timing, some of those resulting jobs end up with the same name. Exceptions are thrown. Jira tickets are raised.

Short of having the Request ID available in Apex to ensure uniqueness I'll need to burn some more characters in the job name. I just need to know how many characters I have to work with.

  • 1
    I'm very aware that this should be an easy thing to answer. My goal is to have something that shows up in Google to save everyone the minute or two to find the actual answer. – Daniel Ballinger Mar 11 at 22:15
  • Every identifier in Apex shares the same length restriction. – Adrian Larson Mar 11 at 22:26
  • 1
    Oh wait, you're not asking about the length of the class name. Derp. – Adrian Larson Mar 11 at 22:28
10

@sfdcfox beat me to it. However, I got the detail of 255 via:

System.debug(Schema.SObjectType.CronJobDetail.fields.Name);

and looking at the output:

Schema.DescribeFieldResult[...;getLabel=Job Name;getLength=255;...]

| improve this answer | |
  • That would have been my second guess... Or, alternatively, I just wanted to play with really big numbers to see what I could come up with :p – sfdcfox Mar 11 at 23:33
10

The maximum length is 255.

System.UnexpectedException: Job Name: data value too large: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... (max length=255)

As an aside, after 4000 characters, you get a different error:

System.AsyncException: failed to get existing job id

| improve this answer | |
  • Who would have thought of 🤔💭 finding it out like this? @sfdcfox I like your approach :-p – Mitesh Mar 12 at 2:55
  • Interesting that pushing past 4000 characters changes the nature of the error. – Daniel Ballinger Mar 12 at 23:44

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.