1

I'm trying to detect which record caused an error when the Approval.ProcessResult process results in an error. The problem that I am having is I cannot relate this error back to the original record that was being submitted. It appears that upon failure one cannot get the result.EntityId()

Does anyone know how to get the record that caused the error during the Approval.process? My goal is to have a visualforce page where a user selects multiple records for approval. Upon error they list should be updated with the corresponding error message of any records that failed. Thanks!

reviewApprovals is a wrapper list of items that I am attempting to submit for approval.

for ( reviewApproval activeApproval : activeApprovals )
{
    Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
    req.setObjectId( activeApproval.reviewApproval.Id);
    submits.add( req );
}

Approval.ProcessResult[] processResults = null;

processResults = Approval.process(submits, false);

string error = '';
for ( Approval.ProcessResult result : processResults)
{

if ( !result.isSuccess())
{
    system.debug( result.getErrors() );
    for ( Database.error strError : result.getErrors() )
    {
        error += '<br/>' + strError.getMessage();
    }
    system.debug('error: ' + error);

    /* doesn't work as we cannot get the result.EntityId();
    for ( integer i=0; i<reviewApprovals.size();i++ )
    {
        if ( reviewApprovals[i].reviewApproval.Id == result.getEntityId())
        {
            reviewApprovals[i].error = error;
        }
     }
    */
}

}

1

The indexes of the results is guaranteed to be the same order of the list that had the DML performed so you can do something like this:

for ( Integer x=0;x<processResults.size();x++){
   if(!processResults[x].isSuccess()){
       system.debug(submits[x].getObjectId()); //this debugs the record ID that was submitted causing the error. you can do whatever you need to besides debug
   }
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.