[SalesForce] Is it possible to retrieve a signed PDF from Docusign and then put it in the Notes & Attachments

We are currently developing an app in Salesforce for docusign in which when we click on a button called, 'Send to Docusign', an Apex code is run and this will push the pdf to Docusign for signing.

Now once the pdf is in Docusign, the client must sign it and then once done, the pdf should be retrieved by Salesforce and then added to the Notes & Attachments section.

Basically, the flow of our app should be:

1 – User clicks on 'Send to Docusign' button in Contracts object

2 – An apex code is run that pushes a PDF to Docusign

3 – Client signs Docusign

4 – Salesforce retrieves signed PDF and adds it to Notes & Attachments

Now we've pretty much figured out 1 to 3 and now we're just brainstorming on 4.

Is this possible?

I'm thinking we might need to code a REST or SOAP function in Salesforce to retrieve the signed PDF but might there be even a simpler solution to this?

Is it possible that it is Docusign that will automatically return the PDF once it is signed and we no longer have to query Docusign from Salesforce if whether the PDF is signed or not?


Best Answer

Yes it's possible, and there is a docusign to Salesforce managed package that lets you connect the two platforms. However if you want to do the custom route because you're productizing this, here is what you would do:

  • On the docusign side, you would create a webhook that would notify salesforce when the docusign status record has a status of completed. On the salesforce side, you could support that with a site. You need the envelopeid from DS
  • In Apex, authenticate and callout to DS.
  • For the envelope get a list of documents that are contained in it. here is some sample code

For the remainder, you want to use this sample code

  • After you have the name or ID of the document to download, use the following procedure to download the document:
  • Instantiate the Docusign API client.
  • Set the following default request header to add your access token (obtained using any of the DocuSign authentication flows or, for testing purposes, the OAuth Token Generator) to all API calls.
    • "Authorization" : "Bearer {Access Token String}"
  • Initialize the Envelopes API.
  • Call the GetDocument API method with your integration key, the ID of the envelope containing the document, and the ID of the document.
  • Specify the output filename, if desired. Confirm the compatibility of the document format prior to deployment in production.

Lastly, I recommend posting this in StackOverflow. There are DocuSign tech people people who monitor and help in that community.

Related Topic