I am fighting with a javascript custom button, I would like to add the behavior to auto populate automatically over the DocuSign envelope the documents.

I'm not able to find a way to make this work

enter image description here

I have already read the below link, but I am stuck.


3 Answers 3


From what I recall in making customizations to DocuSign for Salesforce (DSFS for short) for my company, you can't attach a document to the envelope using Javascript.

In my case, sending quotes out to customers via DocuSign, DocuSign automatically picks up anything (and everything) stored in an Attachment record where the ParentId field matches the Id of the record that you're initiating the envelope from (i.e. the 'SourceID' parameter that DSFS can accept).

You could probably use Javascript to prompt for a file, and then proceed to save it as an Attachment in Salesforce...but it sounds like you're getting to the point where it makes more sense to develop a custom visualforce page (with a controller extension) to take care of this for you. The added benefit to that is that buttons that redirect users to a visualforce page are allowed with the Lightning Experience (whereas Javascript buttons are not).

If you don't need any user interaction besides clicking the button (that is to say, the document you want to send already exists, or can be automatically generated), then your visualforce page can literally be one line

<apex:page standardController="YourObjectNameHere" extensions="YourExtensionNameHere" action="{!extensionMethodThatReturnsAPageReferece}" />

The action attribute specifies a method to be called (in either your controller, or an extension) after the constructor(s) are called, but before the page is rendered. If this method returns a PageReference, the user is then immediately redirected to that PageReference (usually without seeing the blank Visualforce page that preceded it).

If the method that you specify as the action inserts an Attachment, and you return a PageReference to the entry point of DSFS (Page.dsfs__DocuSign_CreateEnvelope), then that should accomplish what you're looking to do here.

Also, because I think you may end up needing it, you may want to download a copy of the DocuSign for Salesforce Administrator's guide. Starting on page 62 (Custom Button Configuration) of that guide is an explanation of all of the parameters that you can pass to DSFS, and what they do.


In the end I met my purpose. I created a javascript button that calls a apex class. The apex class created an envelope dsfs__DocuSign_Envelope__c where I default the document and recipient.

Here you have a part of my class:

        dsfs__DocuSign_Envelope__c newEnvelope = new dsfs__DocuSign_Envelope__c();
        newEnvelope.dsfs__Source_Object__c = quoteId.Id;
        newEnvelope.Quote_Document__c =  defaultQuoteDocument;
        insert newEnvelope;
            System.debug('Control1 ');
            Document document = [SELECT Name FROM Document WHERE Id =: defaultDocument];
            dsfs__DocuSign_Envelope_Recipient__c contact = new dsfs__DocuSign_Envelope_Recipient__c();
            dsfs__DocuSign_Envelope_Document__c newEnvelopeDocument = new dsfs__DocuSign_Envelope_Document__c();
            // New Envelope document
            newEnvelopeDocument.dsfs__DocuSign_EnvelopeID__c = newEnvelope.Id;
            newEnvelopeDocument.dsfs__Attachment_ID__c = defaultDocument;
            newEnvelopeDocument.dsfs__Document_Name__c = document.Name;
            newEnvelopeDocument.dsfs__External_Document_Id__c =defaultDocument;
            newEnvelopeDocument.dsfs__Document_ID__c =  defaultDocument;
            newEnvelopeDocument.dsfs__SFDocument_Type__c = 'Document';
            //Related DocuSign Signer Envelope recipient
            contact.dsfs__DSER_ContactID__c = defaultContact;
            contact.dsfs__Salesforce_Recipient_Type__c = 'CONTACT';
            contact.dsfs__RoleName__c = 'Signer';
            contact.dsfs__DocuSign_Signer_Type__c = 'SIGNER'; //CUSTOMER 1
            contact.dsfs__DocuSign_Recipient_Role__c = 'CUSTOMER 1';
            contact.dsfs__DocuSign_EnvelopeID__c = newEnvelope.Id;

            insert contact;
            insert newEnvelopeDocument;
            return String.valueOf(newEnvelope.Id);

Parameter LA (Load Attachments)is used for this:

LA = '';

or as follows

LA = '1';
  • 3
    Would you be able to expand upon your answer a bit? :-) Aug 8, 2017 at 13:29

You must log in to answer this question.

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