I have a detail page button on a Custom object which updates child collection records. In the extension I'm calling a batch to update the child records on a given criteria. The batch completes with no errors and the logs show that an update List<Sobject> call is made against an expected list of records with updated field values, but the changes are not persisted. Please advice!
Here's the code block:
List<MySObject__c> sobjectsToUpdate = new List<MySObject__c>();
for (MySObject__c obj : objects) {
if ('Some complex condition here') {
if (obj.Type__c == 'Type 1' ) {
obj.Status__c = 'Status 1';
}
else {
obj.Status__c = 'Status 2';
}
obj.Date__c = Datetime.now();
sobjectsToUpdate.add(obj);
}
}
if (!sobjectsToUpdate.isEmpty()) {
System.debug(sobjectsToUpdate); // I have this collection logged, and the records are as expected
Database.SaveResult[] res = Database.update(sobjectsToUpdate, false);
System.debug('All save results: ' + res); //This one is not logged.
for (Database.SaveResult sr : res) {
System.debug('Save result: ' + sr); //Neither this one
}
}
Note: When I execute the batch logic directly in my extension, the collection is updated.
Edit: After further troubleshooting I noticed that the provided code block works for every other value except for: obj.Status__c = 'Status 1';. I don't have Validation rules.
Status__ca restricted picklist, and if so isStatus 1one of the available options? – IllusiveBrian Aug 07 '17 at 17:43