0

I have some code which updates a Custom Metadata setting, something like this:

public void clearValue() {
    Metadata.CustomMetadata customMetadata = createCustomMetadata();
    customMetadata.values.add(createCustomMetadataValue('namespace__Fieldname__c', ''));
    deployMetadata(customMetadata);
}

It works fine.

But when it's called after a scheduled job is aborted:

System.abortJob(jobId);

I am getting this error:

System.UnexpectedException:
Metadata.Operations.enqueueDeployment:
Salesforce System Error: 1393463776-817 (799279837) (799279837)

I cannot find anything online about this.

I am able to work around it by calling System.abortJob from a @future method:

@future
private static void abortJobAsync(Id jobId) {
    System.abortJob(jobId);
}

But then I am unable to ensure all the intended actions completed successfully within the same transaction and report back the user accordingly.

  1. Is this the expected behaviour?
  2. Why is this happening?
  3. Is there a better solution?

1 Answer 1

0

In the end, I got around this error by doing the Metadata.Operations.enqueueDeployment before calling System.abortJob(jobId); rather than the other way around as before. No need for an @future

4
  • Is the job ID the ID for the currently executing Apex?
    – Phil W
    Oct 31, 2020 at 7:55
  • Yes, the Job ID is correct. I checked this.
    – Robs
    Oct 31, 2020 at 9:19
  • Sorry, you misunderstand me; I mean - are you aborting the currently executing apex's scheduled job or a different job?
    – Phil W
    Oct 31, 2020 at 14:22
  • Ah-ha! I get understand now, apologies. No, I am not aborting a job from within it, or should it be executing at that time either.
    – Robs
    Oct 31, 2020 at 14:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .