0

I'm trying to submit for approval using java code. It's seems working, but the issue is when the submit failed (E.g. record doesn't met the entry criteria), I cannot get clear message of the reason.

According to the documentation in SF should use getErrors().toString(), but this give

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_process.htm

Java Code:

ProcessSubmitRequest[] l_processSubmitRequest = new ProcessSubmitRequest[totalRecords];

            for(int i = 0; i < totalRecords; i++){

                ProcessSubmitRequest processSubmitRequest = new ProcessSubmitRequest();
                processSubmitRequest.setComments(comment);
                processSubmitRequest.setObjectId(l_Records.get(i).getId());

                l_processSubmitRequest[i] = processSubmitRequest;

            }

            //Submit all records for approval and check the results
            ProcessResult[] l_processResult = connection.process(l_processSubmitRequest);

            for(ProcessResult processResult : l_processResult){

                if(!processResult.isSuccess()){

                    errorMsg += "\n\nMessage when using getErrors()[0].getMessage(): " + processResult.getErrors()[0].getMessage();
                    errorMsg += "\n\nMessage when using getErrors().toString(): " + processResult.getErrors().toString();
                }
            }

Output is:

Message when using getErrors()[0].getMessage(): <messaging:emailTemplate> cannot contain <apex:pageBlock>.

Message when using getErrors().toString(): [Lcom.sforce.soap.partner.Error;@49e5f737

2 Answers 2

0

Please ignore.

I have internal error with Case approval process (don't know yet why), so I tested this process with opportunity approval and was able to receive the correct error message by using : getErrors()[0].getMessage(): No applicable approval process was found.

0

There couple of reasons behind the issues

  • There is no active approval process defined on the object.

So, define the approval process on this object for which you are passing Id

processSubmitRequest.setObjectId(l_Records.get(i).getId());
  • The approval rule criteria must match to submit the record for approval

To test this whether it is getting submitted or not, define no rule and try to submit, you will see records are getting submitted for approval successfully.

Then, change the rule according to your usecase.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .