function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JeffreyStevensJeffreyStevens 

Echosign from visualforce PDF

We currently use complex Conga merge documents, and then attach them to an Echosign agreeemt.  Well, now I'd like to find a way to drop the Conga documents from the process.  Document is getting even more complex, and I'm going to use visualforce and apex to create the document that is to be signed. So, ...

Can visualforce rendered as a PDF, have embedded signature tags?  

Thanks

 
Best Answer chosen by JeffreyStevens
JeffreyStevensJeffreyStevens
Here is the code that was finally put in place.  Nahuel was close - but I had to actually insert the echosign_dev1__SIGN_Agreement__c record first. 
 
// Build page reference for contract PDF & attach to the contract record		
pageReference pdfPage = Page.ContractPDF;
pdfPage.getParameters().put('ContractId',pContractId);
blob pdfBody;
if(Test.isRunningTest()) { 
  pdfBody = blob.valueOf('Unit.Test');
} else {
  pdfBody = pdfPage.getContentAsPDF();
}
	    	
// Build Echosign agreement record
echosign_dev1__SIGN_Agreement__c agreementRec = new echosign_dev1__SIGN_Agreement__c();
agreementRec.Name									= 'Agreement -  ' + contract.Account.Name + ' - ' + contract.startDate.format() ;
agreementRec.echosign_dev1__Signaturetype__c			= 'e-Signature';
agreementRec.echosign_dev1__Recipient__c				= contract.CustomerSignedId;
agreementRec.echosign_dev1__Recipient_User__c			= administratorId;
agreementRec.echosign_dev1__Recipient_Signing_Order__c	= 'Sequential';
agreementRec.echosign_dev1__Contract__c				    = pContractId;
agreementRec.echosign_dev1__Account__c					= contract.AccountId;
agreementRec.echosign_dev1__Enable_Hosted_Signing__c	= true;
insert agreementRec;
			
// insert the pdf as an attachment and set to the agreement
attachment pdfFile = new attachment();
pdfFile.isPrivate		= false;
pdfFile.body			= pdfBody;
pdfFile.parentId		= agreementRec.id;
pdfFile.Name			= 'Agreement ' + contract.Account.Name + ' - ' + contract.startDate.format() + '.pdf';
insert pdfFile;

 

All Answers

RohRoh
Hey Jeff,
Please take a look at below documentation which gives idea of a way to do this using VF.
http://developer.force.com/cookbook/recipe/accessing-docusign-api-from-salesforcecom-to-send-contracts-for-esignatures

Please vote this as the best answer if it solves your problem.

Thanks,
Roh
JeffreyStevensJeffreyStevens
No - that was for Docusign - I'm using EchoSign
NahuelNahuel
Hey Jeffrey, were you able to figure out an answer to your question?. Im in a similar situation right now :).

Cheers!
JeffreyStevensJeffreyStevens
@hahuel - FYI - I'm getting back into this today and tomorrow.  I'll post here if I have any success.
NahuelNahuel
Hey @JeffreyStevens, we ended up using Docusign :). In case this helps:
- Im creating a VF renderedAsPDF and inserting docusign anchor tags /s1/, /s2/ etc. Then sending with Docusign standard button attaching this documents. Docusign pulls up the hidden anchor tags in the doc to automatically place signing points.

Cheers and good luck!
JeffreyStevensJeffreyStevens
Good to know, thanks.

When you do the renderAsPDF - how do you attach the PDF to the DocuSign call?  I do several renderAsPDF, but I sually launch the pdf in the browser - for interactive presentation.  So, I've never created the PDF as an actual attachment or something like that.

Got any code  you can share on that?
NahuelNahuel

Well, for a fully automatic 1 click solution you can use Docusign SOAP Api. This solution works as I have managed to get it working with some guide from the internet. The problem with this solution is that if you want to use Docusign SOAP against a Docusign Prod Account (and not a Demo Docusign Account) you have to go trough a dev certification process with them which at the time I did that it costed around 1k and could take 1/2 weeks. 

At that point, my quick workaround was this -> Have a button that generates the VF as PDF and adds it as an Attachment on the Opportunity. The standard Docusign "Send with Docusign" button on the Opportunity pulls up the Attachments automatically, so it would pull my generated "DocumentToSign.PDF". 

This is not so automatic but its just 2-3 clicks to send a doc which is not that bad either.

To create the VF PDF and use it as an attachment you have to use the getContentAsPDF() method which is in the Summer 15 release.
https://help.salesforce.com/apex/HTViewSolution?id=000213972&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000213972&language=en_US)
http://releasenotes.docs.salesforce.com/en-us/summer15/release-notes/rn_vf_getcontent_callout_cruc.htm?edition=&impact= (http://releasenotes.docs.salesforce.com/en-us/summer15/release-notes/rn_vf_getcontent_callout_cruc.htm?edition=&impact=)

Cheers!

NahuelNahuel

Sample code:

PageReference pdf =  Page.PageRenderedAsPdf;
pdf.getParameters().put(URL_PARAM_KEY,URL_PARAM_VALUE);
pdf.setRedirect(true);
// Take the PDF content
Blob blobContent;
if (Test.IsRunningTest()){
    blobContent = Blob.valueOf('TEST');
} else {
    blobContent = pdf.getContent();
}
// Prepare and upload attachment
Attachment attach = new Attachment();
attach.Body = blobContent;
attach.Name = 'Document.pdf';
attach.IsPrivate = false;
attach.ParentId = OpportunityId;
insert attach;
We need to add that Test.IsRunningTest because it is treated as a Callout.
Good luck!.
PD: I am just starting to use this forum and it seems people get their answers "voted" if they help resolve the issue, so, if any of my answers steer you in the solution of your problem, please vote me up ;). 
JeffreyStevensJeffreyStevens
Here is the code that was finally put in place.  Nahuel was close - but I had to actually insert the echosign_dev1__SIGN_Agreement__c record first. 
 
// Build page reference for contract PDF & attach to the contract record		
pageReference pdfPage = Page.ContractPDF;
pdfPage.getParameters().put('ContractId',pContractId);
blob pdfBody;
if(Test.isRunningTest()) { 
  pdfBody = blob.valueOf('Unit.Test');
} else {
  pdfBody = pdfPage.getContentAsPDF();
}
	    	
// Build Echosign agreement record
echosign_dev1__SIGN_Agreement__c agreementRec = new echosign_dev1__SIGN_Agreement__c();
agreementRec.Name									= 'Agreement -  ' + contract.Account.Name + ' - ' + contract.startDate.format() ;
agreementRec.echosign_dev1__Signaturetype__c			= 'e-Signature';
agreementRec.echosign_dev1__Recipient__c				= contract.CustomerSignedId;
agreementRec.echosign_dev1__Recipient_User__c			= administratorId;
agreementRec.echosign_dev1__Recipient_Signing_Order__c	= 'Sequential';
agreementRec.echosign_dev1__Contract__c				    = pContractId;
agreementRec.echosign_dev1__Account__c					= contract.AccountId;
agreementRec.echosign_dev1__Enable_Hosted_Signing__c	= true;
insert agreementRec;
			
// insert the pdf as an attachment and set to the agreement
attachment pdfFile = new attachment();
pdfFile.isPrivate		= false;
pdfFile.body			= pdfBody;
pdfFile.parentId		= agreementRec.id;
pdfFile.Name			= 'Agreement ' + contract.Account.Name + ' - ' + contract.startDate.format() + '.pdf';
insert pdfFile;

 
This was selected as the best answer
Matthew Whaley 17Matthew Whaley 17

Nahuel was the code you used above used in the Controller of the Visualforce page? How did you include the EchoSigns tags in the Visualforce PDF?

NahuelNahuel

@Matthew: You probably want to create a new question so we don't revive this thread for people who are not interested in this new concern. 

Having that said, I used "Docusign", not Echosign. And with Docusign, I just had to place some hidden tags within the PDF for Docusign to pick up the location to place the digital signature.
Something like this:

VF:
 

<p>{!SIGNATURE}</p>

Controller:
public String SIGNATURE {get{return '\\s1\\';}}

You have to check in the documentation what you need to add for the digital signature placement, surely Echosign has something similar, in this case it's "\s1\".

Hope that helps!,
Nahuel.
JeffreyStevensJeffreyStevens
Here is how I have the EchoSign tags in the VF PDF page...
 
<div id="signatureTable" style="position:relative;top:20mm;text-align:center;">
		<table style="border:1px solid #eaeaea;">
			<tr style="height:50px;background-color:#eaeaea;vertical-align:text-bottom;text-align:left;font-size:10pt;font-weight:bold;border-bottom:1px solid #eaeaea;">
				<td colspan="2">OurName</td>
				<td colspan="2">Account</td>
			</tr>
			<tr style="height:50px;vertical-align:middle;text-align:left;border:1px solid #eaeaea;">
				<td width="30mm">Signature:<br/><div style="font-size:8pt;">Name/Date:</div></td>
				<td width="150mm" style="color:#ffffff;">{{Sig_es_:signer2:signature}}</td>
				<td width="30mm">Signature:<br/><div style="font-size:8pt;">Name/Date:</div></td>
				<td width="150mm" style="color:#ffffff;">{{Sig_es_:signer1:signature}}</td>
			</tr>
		</table>
	</div>

When you do that - and the Agreement get's executed - then Echosign will update the Agreement record(s)
Ryan GreeneRyan Greene
@JeffreyStevens 
I am deploying a similar code as you have as best answer. I am receiving some erros such as pContactID and Page.ContractPDF don't exist. Am I missing something?
Thank you,
Ryan
JeffreyStevensJeffreyStevens
ContractPDF is a visualforce page (renderedas=PDF) - that is called from a button on a Salesforce record.  So the controller for the ContractPDF page would be creating a variable called pContactID, and - it's probably trying to get the value from the URL - the button definition would have put it in there when the /apex/ContractPDF page was called.
Harshada Kadu 12Harshada Kadu 12
@JeffreyStevens
I have a similar requirement to embedd echosign signature tags in VF page.
As seen from the above discussion it seems you have done it. Will you please help me with it as this is the first time I am working on e-sign.
Thanks,
Harshada