function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CreatobugCreatobug 

How can I identify the record for which the approval process failed

Approval.ProcessResult is supposed to have fields which identify which record is being processed (getEntityId()). However, this seems to be null for the records for which the approval process fails. Is this the expected behaviour?

Sample Code:
           Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
           req.setComments('Approval Comments');
           req.setObjectId(<Record ID>);
           LApproval.ProcessResult result = Approval.process(req, false);
           System.debug(result);

So how can we identify those records for which the approval process fails?
KevinPKevinP
I've seen this happen before, and the best I've been able to do is ensure the record id is recorded in a machine readable way in the comment. I suggest a simple json wrapper class.
CreatobugCreatobug
@KevinP Could you elaborate on your suggested solution.
Big EarsBig Ears
A good answer can also be found here: https://salesforce.stackexchange.com/questions/120781/approval-process-submit-for-approval-in-bulk-error/120786#120786

The requests and results will be in the same order and the id will be recorded in the requests.