2

I had created a simple custom button to submit a custom object to an Approval process with a URL:

<a  role="button"
    class="btn" 
    style="text-decoration:none;background:#99C299; font-size:16pt; font-family:arial;"
    href = "/p/process/Submit?id={!DS.Id}&retURL=%2F{!DS.Id}"
    target = "_self">
    <b>Submit For Final Approval</b>
</a>

I now get the error message "We need to confirm that your request is valid. Please repeat your last action." whenever I click the button. It seems as though Salesforce disabled the ability to use the standard URL in my button.

I now tried creating a custom controller with a method to create the approval through Apex:

    public class DSReviewController {

       public Deal_Summary__c myDS;

        public DSReviewController(ApexPages.StandardController stdController){
            this.myDS = (Deal_Summary__c)stdController.getRecord();
        }

        public void approve() {
            // Create an approval request for the Deal Summary
            Approval.ProcessSubmitRequest approve1 = new Approval.ProcessSubmitRequest();
            approve1.setComments('Submitting request for approval.');
            approve1.setObjectId(myDS.id);

            Approval.ProcessResult result = Approval.process(approve1);
        }
}

And I changed my custom button in my VF pages to:

<apex:commandButton action="{!approve}" styleClass="buttonStyle" style="background:#99C299; font-size:16pt; font-family:arial;" value="Submit for Approval"/>

However, when I click the button, nothing happens. Can anyone help?

2 Answers 2

1

This is an intentional change which has been made by Salesforce in Winter'16 release to remove security vulnerability.

Staring Winter'16, you will not be able to use the Custom Buttons to call standard URL for Approval Process Submission (which is "/p/process/Submit?... ").

When you use this, you will get an error : "We need to confirm that your request is valid. Please repeat your last action"

You can visit this link for the workarround. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_process_example.htm

or

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_process_approvals_submit.htm

3
  • Thanks Ricky. Yes, I saw that from Salesforce, I'm just not sure how to call a class in a custom button on a VF page or the JSON option.
    – J. Neilan
    Commented Oct 14, 2015 at 18:08
  • @J.Neilan - Then I would think that should be your question then correct?
    – Eric
    Commented Oct 14, 2015 at 18:19
  • Eric, I edited my original post to include where I am now.
    – J. Neilan
    Commented Oct 14, 2015 at 18:41
1

Final Code:

public class DSReviewController {
    public Deal_Summary__c myDS;
    public DSReviewController(ApexPages.StandardController stdController){
        this.myDS = (Deal_Summary__c)stdController.getRecord();
    }

    public void approve() {

        Approval.ProcessSubmitRequest approve1 = new Approval.ProcessSubmitRequest();
        approve1.setComments('Submitting request for approval.');
        approve1.setObjectId(myDS.id);

        approve1.setProcessDefinitionNameOrId(null);
        approve1.setSkipEntryCriteria(true);

        Approval.ProcessResult result = Approval.process(approve1);
    }
1
  • this is the final code that allows submission?
    – jaw999
    Commented Jun 16, 2017 at 19:25

You must log in to answer this question.

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