I'm running the following code, and I just want to log the total amount of deletes, and the total amount of records passed into the method and return the total amount of records that were processed and the total amount of deletes. However, the the debug logs appear to be adding these two numbers together. what am I missing here?

High Level Process

Schedule Class --> Batch Class --> Queueable Class --> Managed Package Future Method Triggered by Update performed in Queueable Class

Code: Queueable Class

public with sharing class Queable_RemoveCustomers implements Queueable {

   List<Customer__c> customers = new List<Customer__c>();
   public Queable_RemoveCustomers(List<Customer__c> customers){
       this.customers = customers;

   public void execute(QueueableContext context) {
       Integer totalDeletes = 0;
       Integer errors = 0;
       System.Debug('QUEUED UP');
       System.Debug('Customers ='  + customers.size());
       List<Database.SaveResult> updateResults = Database.update(customers, false);

            for (Database.SaveResult result : updateResults) {
                if (!result.isSuccess()) {
                } else {

        System.debug('DELETE Payload = ' + customers.size());
        System.Debug('SUCCESSFUL DELETES = ' + totalDeletes);
        System.Debug('FAILED DELETES = ' + errors);



The output to the log is the following:

Customers = 142 DELETE Payload = 142 SUCCESSFUL DELETES = 284 FAILED DELETES = 0

  • You say there is a managed package future method after the Queueable in your transaction chain, but your code sample seems to contradict that. – Adrian Larson Dec 9 '19 at 16:15
  • The update to the record triggers the future method. This future method is not something we have access to, but not sure it should have an impact on the different numbers here in the log... – thinker Dec 9 '19 at 16:15
  • 2
    You didn't over-simplify your code by chance, did you? The total number of records processed must equal the original list size. There's absolutely no way I know of that this could happen, so I presume you've cut out some code that would explain it. – sfdcfox Dec 9 '19 at 17:04
  • 1
    since you are using allOrNothing = false; if there are any errors, SFDC will retry the DML on the successes; this could account for the variance in counts - see Order of Execution, Additional Considerations, second bullet - I'm not convinced this is the issue but worth examining – cropredy Dec 9 '19 at 18:04
  • I am passing the list size from a batch process. I just ran it again though, and the numbers did not double; I did not make changes to the code to fix the issue either. Have any of you ever seen this behavior. – thinker Dec 10 '19 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.