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.
- Is this the expected behaviour?
- Why is this happening?
- Is there a better solution?