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

Echosign integration send an agreement from code

Looking for a way to SEND Echosign agreements from code.

I have echosign installed and it's working well. I also build the agreement from code and it works well. Now, I would like to actually do the SEND from code.  

So far - all of the examples I have seen - have been for creating a custom SEND button - utilizing the AgreemenTemplateProcess VF page, and specifiying the MasterID.  But - in this case - I've already built the agreement, and custom PDF attachment.

Any thoughts?

Best Answer chosen by JeffreyStevens
I finally found the solution.

I changed the field echosign_dev1__Background_Action__c to "Send" and updated the echosign_dev1__SIGN_Agreement__c object record, and it sent the agreement out.

All Answers

Scott Haleo 4Scott Haleo 4
Hi Jeffrey,

You can check the details in below link might help you.

If you are ok in this link let me know And you can also share with me if you have any other issues?

Scott Haleo
Thanks - however that link doesn't show how to do the actual SEND with code.  And I'm not using templates, I'm creating a PDF with the embedded merge and signature fields, then building the Agreement record, then attaching the PDF to do.  All works well, but now trying to do the same functionality as the "Send" button.
I finally found the solution.

I changed the field echosign_dev1__Background_Action__c to "Send" and updated the echosign_dev1__SIGN_Agreement__c object record, and it sent the agreement out.
This was selected as the best answer
Matthew Whaley 17Matthew Whaley 17
Hey Jeff I am looking to do something exactly like you where you are creating a PDF with embedded merge and signature fields, building the agreement record and attaching the PDF to the agreement. I am wondering what resources you found that was helpful in that process. Most of what I have come across has been for DocuSign.
Ya - there wasn't much in way of resources that helped me.  I just kind of figured out on my own that I had to build the echosign_dev1__SIGN_Agreement__c record.  Once I built and inserted that record - things started working better. 

So, here is the code in my controller...
public pageReference buildContract() {
		// Get Contract ID from URL
		string pContractId = ApexPages.currentPage().getParameters().get('contractId');
		list<string>	validationErrors = validationCheck();
		if(validationErrors.size()==0) {

			// Build page reference for contract PDF & attach to the contract record		
			pageReference pdfPage = Page.ContractPDF;
	    	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										= 'Master 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		=;
	    	pdfFile.Name			= 'Master Agreement ' + contract.Account.Name + ' - ' + contract.startDate.format() + '.pdf';
	    	insert pdfFile;
			return new pageReference('/' +;
		} else {
			for(string errorString :validationErrors) {
				ApexPages.addmessage(new ApexPages.Message(ApexPages.Severity.ERROR, errorString));
			return null;

So, basically - I have the page that produces the PDF content.  (with the embedded {{Sig_es_:signer2:signature}} code for the actual signature line). I build a blob of that page, then I build the echosign_dev1__SIGN_Agreement__c record - filling in most of the fields.  After it's inserted - then I link to that record and make them do the actual "Send".  I think there is a field that can be set that makes the Send automatic though.   

Hope that helps