1

I have written logic that enqueues queueable class from trigger of one object. This works perfectly when I update records and all records gets updated successfully,but in case of partial success I can get the job id in trigger but queueable class execution is not happening.

To illustrate :

trigger accountTrigger on Account(before update) {
Map<Id, Account> tempMap = new Map<Id, Account>();  
for(Account acc : trigger.new){
      if(acc.Name == 'Test Account')
         tempMap.put(acc.Id,acc);
   }
if(tempMap.size()>0){
  String jobId = System.enqueueJob(new QueuebleUtility(JSON.serialize(tempMap));
  System.debug('Job Id :'+jobId);
 }
}


//Queueable class
public with sharing class QueuebleUtility implements Queueable {
    public String jsonString;
    public QueuebleUtility(String jsonString) {
        this.jsonString = jsonString;
    }

    public void execute(QueueableContext context) {
        System.debug('jsonString : '+jsonString);
    }
}

In case of all success, - I can see job id as well as queueable gets executed(log file generated) In case of partial success - I can see job id but queueable doesn't execute (log file is not generated)

Is there any behavior of Salesforce that all asynchronous jobs will be rolled back in case of partial success of DML?

1

Yes, this is standard logic. When a DML operation starts, a "check point" is implicitly created. During the partial DML operation mode, if any records get an error, the transaction is rolled back to this check point, including any emails sent, jobs queued, future methods, etc. The records that received errors are set aside, and the remaining records are processed again. If at least one record survives the final transaction, all other records (including emails sent, jobs queued, etc) are committed and executed. This means it is possible for a job to have been "queued" but then immediately removed as a result of an error. See Transaction Control for more information.

| improve this answer | |

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.