The update here completes without issue. That's not what I was expecting after locking the record. Please advise.
public static Map<String, String> undoNotAwarded(String[] quoteIdsArray){
Map<String, String> toastVariantToMessage = new Map<String, String>();
String vendorList = '';
List<Custom_Quote__c> quotes = [SELECT Id, Vendor_Name__r.Name, Status__c
FROM Custom_Quote__c
WHERE Id IN :quoteIdsArray];
lockQuotes(quotes);
for(Custom_Quote__c quote : quotes) {
quote.Status__c = 'Ready for Review';
vendorList += quote.Vendor_Name__r.Name + ', ';
}
try {
update quotes;
} catch(Exception e) {
system.debug(e.getMessage());
String message = 'An error occurred. Emails were not sent to: ' + vendorList;
toastVariantToMessage.put('error',message);
return toastVariantToMessage;
}
String toastMessage = 'Status set to \'Ready for Review\' on these quotes: ' + vendorList;
toastVariantToMessage.put('success',toastMessage);
return toastVariantToMessage;
}
LockQuotes Private Method
private static void lockQuotes(List<Custom_Quote__c> quotes){
Approval.LockResult[] approvalLock = Approval.Lock(quotes, false);
for(Approval.LockResult al : approvalLock) {
if (al.isSuccess()) {
System.debug('Successfully Locked Quote with ID: ' + al.getId());
}
else {
// Operation failed, so get all errors
for(Database.Error err : al.getErrors()) {
System.debug('The following error has occurred.');
System.debug(err.getStatusCode() + ': ' + err.getMessage());
System.debug('Quote fields that affected this error: ' + err.getFields());
}
}
}
}
Approval.lock(quotes, false)
will keep going even if there were errors. Make sure you check your logs.