Accessing DocuSign API from Salesforce.com to send ... .fr

May 6, 2012 - Before getting started you need to get a free Salesforce.com developer account at https://developer.force.com and a free DocuSign developer ...
356KB taille 150 téléchargements 1007 vues
Accessing DocuSign API from Salesforce.com to send Contracts for eS...

1 sur 5

http://developer.force.com/cookbook/recipe/accessing-docusign-api-fr...

Cookbook Login

JOIN NOW

Search

Home

Technical Library

Boards

Cookbook

Code Share

Blogs

Partners

Search Help

More

Cookbook Home » Accessing DocuSign API from Salesforce.com to send Contracts for eSignatures.

Accessing DocuSign API from Salesforce.com to send Contracts for eSignatures. Post by Mike Borozdin (2010-09-29)

Subscribe to this recipe

Status: Unverified

View source code

Level: intermediate Apex (15) ,

App Logic (52) ,

Verify this Recipe

Collaboration (7) , esignature (2) ,

Integration (57) , Web Services API (12)

Problem You want to access the DocuSign API in your Force.com / Salesforce.com account in order to send an object with a single click of a button.

Solution Before getting started you need to get a free Salesforce.com developer account at https://developer.force.com and a free DocuSign developer account at [url www.docusign.com/devcenter]www.docusign.com/devcenter. 1. Start out by adding DocuSign webservices to your authorized endpoints for your Salesforce.com developer account. To do this, go to Setup > Security > Remote Sites and add https://demo.docusign.net/api/3.0/dsapi.asmx. 2. Next, set up a Salesforce.com site so you can test rendering pages. There is plenty of documentation on how to get started with VisualForce, so we will leave it up to Salesforce.com to explain the best options there. For the purpose of this walkthrough you just need to have a site for testing. You can get to the screen below by clicking Setup > Develop > Sites.

From there you can create a site label. Once the site is created all you need to do is make it active.

3. Now we need to create two pages; one for rendering a contract as a PDF and another that makes a web service call to DocuSign. We will start with the rendering page that we will call RenderContract (Note: the second page is set up in step 8). The code for the rendering page is fairly minimal. As you can see below, it just uses

6/5/2012 3:39 PM

Accessing DocuSign API from Salesforce.com to send Contracts for eS...

2 sur 5

http://developer.force.com/cookbook/recipe/accessing-docusign-api-fr...

the standard Contract controller class and we are just rendering standard contract details with a couple of signature lines.

' & * + , -

! ! !

" #$ % & ! " ! (((((((((((((((((((((((((((((((((((( " ! )

! ! !

" #$ % & ! " ! (((((((((((((((((((((((((((((((((((( " ! . /

The page needs to be added to the site to ensure that you can access it for testing. You can accomplish that by going to the site detail and selecting Site VisualForce Pages.

The other setting that has to be adjusted for testing is adding Contracts as something that is accessible from this site. To accomplish this go to Public Access Settings and edit the standard object permission.

4. In order to test the first page and other code in our sample, we will create a test Contract. For simplicity we are going to put a contact in the Customer Signed By field.

At this point in time we have all the test data we need. You can note the Contract object ID in the URL https://na7.salesforce.com/800A0000000Q8ol And then use it to test the rendering page by plugging in the ID there: http://devcenter-demo-developer-edition.na7.force.com/apex/RenderContract?id=800A0000000Q8ol At this point you should be getting a PDF file. 5. In this step we are going to create a class to access the DocuSign API. For this walkthrough we are just going to get the sending WSDL, which can be found at https://demo.docusign.net/api/3.0/Schema/dsapi-send.wsdl. You should save the WSDL file to your desktop. (Note: For complete set of WSDL files please refer to documentation on DocuSign DevCenter.) Next go to the Apex Classes and select “Generate from WSDL”. When the class generator asks you to supply a class name, we suggest that you overwrite the class name with DocuSignAPI. 6. Using the new API endpoint, you can create a controller for the second page. In order to do this you need to go to Apex Classes again and create a new class. The code for the controller class is shown below:

6/5/2012 3:39 PM

Accessing DocuSign API from Salesforce.com to send Contracts for eS...

3 sur 5

0

"

"

/

1 .

/

http://developer.force.com/cookbook/recipe/accessing-docusign-api-fr...

2

# ' & * + , -

3 3 3 0 0 6/ $ 8

!" /

1 .

/

3

!>

2

# !!# !!# !!# 5 7 8

#4

!!# 8 9

8

:

$ !#

8/

;

2 ' & * + , -

8


09;#

.

/

3 =

$

/ 8

3 = ?

3 =

> $6

9;83 @#

!#

4 /

> 09;

2 ' & * + , -

' & * + , ' ' ' ' '' '& '* '+ ', '& & & & &' && &* &+ &, &* * * * *' *& ** *+ *, *+ + + + +' +& +* ++ +, +, , , , ,' ,& ,* ,+ ,, ,-' -& -* -+ -, --

:38 :3/ . / 8

/ /

" " ! . / $ : 0 A! 7 A ! : 0 3 5 A ! 3 8 6 9!/ / /

.

/

8 8 ";#

B B

:38E 8/ 6F

A

8 )

8E$ ! !

0

8 )

? ?

7

( ( 8

C 9!D%.

/

.

/

!:

/ " > $6 # !1" $

6

.

$

$

B B

"

3

!# ! A

0

/ 0

!;# ? != 9;#

: 9!

9;8 ? 8

!A 5 ";#

= %

9;# "

!=

:38E !

9;# =!A

" !#

0 3 #

" 9!? : 6

9;# #

0 ! A

? 8 )

6

.

6

/ / 7

! A 5 . / "

$ = 3

= 8

? :

/ :38 :3/ ( 0 6/

"

9! 83 ;#

= ! A

?

!;#

$ / $ $ $ $

:38. $ 83. # 8 ) E 8> $ ! 8G E 8. $ 8. $ 8. 8. $ 8.

$

. 7

!# ! . $ $

86

!# /

< @

/

:38.

*'E

:38 . / $

9

$ )

9;#

6;#

H . $ 9;# :38. $ < @# #

? 8

6

9!

"
$

1" 1" /

$ !! $8D$ 8D$ 8? I 3. 8? 8? 8?

1 6 . / 6 81 6 8? 6 8. 6 8 6 8 . 6 6 6 6 6

/ 81 8? 8. 8 8

8 2 . 4

> $

6

9

:38E / 8 3 8E E

:38?

9;#

8

> $ #

" ) 81 )

J

8 ;

9/ #

.

9!

3 @#

A ! ! A

I

/

:38 .

/

< @

:381 6 6 ( !. / 3. # $ 3. # " 1 63 $ " 1 63 $8 "

/

/

> $ /

# 8G

8? 8?

6 . 6 81 6 6 81 6< @ 6 81 6< @

> $ = 8 $ .

!# # 8E$

:381 6 6 . / ( !/ B !# 3. # $ 3. # " 1 63 $ . / " 1 63 $8 " 1 6/

81 81 81 81 ' & * + , -

!;# = G

$

. !#

/

. / 1 6/ / .

H ? :38? #

9;# < @#

:381 69;#

:38 " 1 69;# !) !# :381 69;#

:38 " !.

1 69;# / !#

:38 H 1 69;# / :381 6< @# 6 # 6 #

"

:3!;#

/ /

E 3.# ; 2

9

;#

6/5/2012 3:39 PM

Accessing DocuSign API from Salesforce.com to send Contracts for eS...

4 sur 5

8

6 3

9!E !E

% ! A % ! A

http://developer.force.com/cookbook/recipe/accessing-docusign-api-fr...

;# #

4 ' & *

4 4

This might seem like a lot of code to understand, but the basics are pretty simple and you can see how a DocuSign envelope is constructed here: http://wiki.github.com/docusign/DocuSign-eSignature-SDK/code-walkthrough-create-and-send-envelope 7. In order to use DocuSign API, you need to retrieve your DocuSign API credentials. Go to https://demo.docusign.net, sign into your demo account, and then go to Preferences > API. There you will find these values: Integrator's Key: ZORO-a81ec71a-cb17-4af0-b1aa-9513115cbf02 API UserName: 0e212ae6-1e12-40c1-8f5a-a57458ccaa63 API Password: API Account ID: 736e7948-6861-4ef3-ae71-4c56603dc14f Plug these values into the controller class. 8. The next step is to create the second page, which actually calls SendToDocuSign. You will add this page to the site and hook it up to the custom controller we just developed: / " " ' & * + , -

K

/ $ $$ $

I )

6 /

. L

1 . :3L "

/ 2L/

/

> 04

" 1"

.

/

E

3

2L

3 4 6

Now you should be able to test sending of the contract by calling the page with the same ID you used for testing the rendering page: http://devcenterdemo-developer-edition.na7.force.com/SendToDocuSign?id=800A0000000Q8ol 9. The last step is creating a custom button on the contract object that calls the sending page. Go to Setup > Customize > Contracts > Buttons and Links and create a New button. In the properties, select Detail Page Button and then add the URL with the Contract Id: /apex/SendToDocuSign?id={!Contract.Id} Add the button to the page layout for the Contract object. This lets your users click on the button to get their Contracts electronically signed! They don’t need to learn any other systems or follow complicated steps. The logic behind the button does all the work.

Share

Recipe Activity - Please Log in to write a comment I followed your example, and am getting this error ( An Error Occurred during anchor tag processing. Invalid document ). Any idea why that might be happening? by Jamie Ayer (2012-03-07) Mike, Great article. I am particularly interested in implementing this task without a user' s click (automatically sending contracts upon ' before insert'of an account). Is there some way to access the DocuSign API from a trigger and use a precreated template/envelope to send? Thanks by a093000000D8LOz (2011-08-23) I have error like: The DocuSign EnvelopeId:Exception - System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: Unspecified_Error faultcode=soap:Server faultactor=https://demo.docusign.net/api/3.0/dsapi.asmx. Can you tell me by Julio Julio (2011-08-21) I would really need help in writing the test case for the above controller.

6/5/2012 3:39 PM

Accessing DocuSign API from Salesforce.com to send Contracts for eS...

5 sur 5

http://developer.force.com/cookbook/recipe/accessing-docusign-api-fr...

by Sayame (2011-06-06) @Sayame - you dont need to render it. All you need to get is just PDF bytes. by Mike Borozdin (2011-06-05) I already have a PDF document stored under Documents on my salesforce with the contract terms.Therefore i don' t need to render any contract from the contract object. How do i get to access my ready made contract under the Document object since i no longer need the RenderContract page? by Sayame (2011-05-25) How can you get the signed contract pdf attached back in salesforce Contract? by Rishi Wadhwani (2011-05-05) I have one requirement where i want to override the behaviour of Documentum Object and Content version object and want to store them on FTP instead of storing it on cloud because of secret documents. Can you tell me how to achieve this by overriding the behaviour of these classes? If you have any sample code, please email me at [email protected]

Thank you Kulveer SIngh by Kulveer Singh (2011-04-07) Hi Nitish! Sorry it took a while to respond. I wish there was an e-mail notification when someone posted a question. Here is something you can try - can you pull up the second page directly? You should be able to just pull it up with an ID of the SF objects. If you have any problems - let me know. by Mike Borozdin (2011-01-20) Hi Nitish! Sorry it took a while to respond. I wish there was an e-mail notification when someone posted a question. Here is something you can try - can you pull up the second page directly? You should be able to just pull it up with an ID of the SF objects. If you have any problems - let me know. by Mike Borozdin (2011-01-20) Hi Mike, I implemented this logic but getting error like "System.CalloutException: IO Exception: Read timed out", when I call my seconf vf page with my contract id.Please help me regarding the same. by nitish dharm (2010-12-08)

Follow us on

United States | 1-800-no-software | Privacy Statement | Security Statement | Terms of Use | Contact Us

© Copyright 2000-2011 salesforce.com, inc. Web-based Customer Relationship Management (CRM) Software-as-a-Service (SaaS). All rights reserved Various trademarks held by their respective owners. Salesforce.com, inc. The Landmark @ One Market, Suite 300, San Francisco, CA, 94105, United States General Enquiries: 415-901-7000 | Fax: 415-901-7040 | Sales: 1-800-no-software

6/5/2012 3:39 PM