I am looking at building my own e-signature plugin for CPQ since I just can't get the Docusign provided one to work correctly. The plugin requires me to return a redirectURL for the e-signature application and I want to just redirect to the dsfs__DocuSign_CreateEnvelope page with a lot of parameters. This is similar to making a custom button, but I'm hoping to do it in code to skip a step.

When I try returning the redirectURL, I get an error: The link you followed isn’t valid. This page requires a CSRF confirmation token. Is there a way to get the CSRF token added as a parameter in Apex? Here's my code so far.

    PageReference pr = Page.dsfs__DocuSign_CreateEnvelope;
    return pr.getUrl();

CPQ is using JavaScript to redirect the user using sforce.one.navigateToURL(redirectURL)

The Docusign built integration sends the user first to a page that doesn't require CSRF and an OK button the user has to click and it builds the URL using URLFOR in the Visualforce page. I can replicate that, but was hoping to skip the intermediate page.

The reason I'm even trying to roll my own is that the Docusign built integration doesn't give me enough control over the parameters sent to the CreateEnvelope page. I want to use merge fields from the related object and Docusign's envelope configuration only lets me put in static values.

  • The way you're doing it has worked for me. You don't need to add in the CSRF token. The page should have the 'require CRSF token' checkbox tick and salesforce automatically adds it for you. How are you navigating to the page?
    – Nick C
    Commented Oct 22, 2019 at 4:20
  • The URL string is passed back to CPQ and it redirects the user. I'm not sure what mechanism it is using to navigate to the page. Commented Oct 22, 2019 at 12:02
  • It looks like CPQ is using sforce.one.navigateToURL(redirectURL) to navigate to the page. Commented Oct 22, 2019 at 14:03
  • How do you set redirectURL? How would you put the result returned from your method into the navigateToURL?
    – Nick C
    Commented Oct 22, 2019 at 22:38
  • That's handled by CPQ. I just need to pass a string that represents the URL back to CPQ. The string needs to include the CSRF token parameter, but it isn't. Commented Oct 23, 2019 at 14:50

1 Answer 1


This isn't really what I wanted to do, but this is the best solution I've come up with for this situation with CPQ where I can't return a PageReference and have to return a string.

I created a redirect page that doesn't require CSRF and it then redirects the user on to dsfs__DocuSign_CreateEnvelope using URLFOR to create URL with a CSRF token.

Here's my method in the CPQ plugin:

   global String sendWithRedirect(List<SBQQ__QuoteDocument__c> documents) {
        SBQQ__QuoteDocument__c qd = documents[0];
        PageReference pr = Page.CPQDocusignLaunch;
        pr.getParameters().put('id', qd.Id);
        return pr.getUrl();

And my intermediate Visualforce page that does the redirect:

<apex:page standardController="SBQQ__QuoteDocument__c" showHeader="true">
    <apex:slds />
    <script src="/soap/ajax/47.0/connection.js" />
    <script type="text/javascript">
    function init() {
        redirectURL = "{!URLFOR($Page.dsfs__DocuSign_CreateEnvelope) + SBQQ__QuoteDocument__c.DocuSignParameters__c}";
        if (sforce && sforce.one) {
        } else {


You must log in to answer this question.

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