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()) {
System.debug(result.getId());
System.debug(result.getErrors());
errors++;
} else {
totalDeletes++;
}
}
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