[SalesForce] How to control redirect on approval submit

Question

Is there a URL parameter I can use to control the page a user lands on after submitting a record for approval?

Background

I'm building out an approval process that is built on an object (agreementApprovalId property of the extension) related to the primary object (Apttus__APTS_Agreement__c). I've built a helper page on the parent object that calls the submit action on the child. Now I need to get Salesforce to return them to the parent object once the approval is submitted.

I've inspected the standard url which uses the retURL parameter, but the system ignores the value I pass in. Is there a different parameter I should be using?

Visualforce Page

<apex:page standardController="Apttus__APTS_Agreement__c" extensions="AgreementApprovalRedirect" 
        action="{!IF(agreementApprovalFound,
                     URLFOR($Action.Discount_Approval__c.Submit,
                            agreementApprovalId,
                            [retURL = '/' + Apttus__APTS_Agreement__c.Id]),
                     null)}">
</apex:page>

Best Answer

Since you are already using a VF page for helping the approval submission why not create an method with return type of pagereference in your AgreementApprovalRedirect extension and use it to redirect to the desired page?

The code would look something like this:

Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();  
req1.setComments('Submitted for Approval');
req1.setObjectId(agreementApprovalId);
Approval.ProcessResult result = Approval.process(req1); 

if(result.isSuccess)
{
  return new pagereference('pageURL');
}
Related Topic