Echosign/Adobe Sign Data Validation before Sending a Contract

In this post I will show how you can validate that all the relevant data has been entered for a contract when using Adobe Sign (formerly Echosign) with Salesforce. Usually a Echosign contract is generated by clicking a button on a record in Salesforce. This method avoids using any javascript buttons and as it uses apex and a visualforce page.

I will share the code in this post which means that the user never gets brought to the Echosign page if all the required data has not been entered. I also combine the apex with a formula field so that changes to the contract validation can be made by simply updating the formula field.

A standard Adobe Sign button passes the user to the urlĀ /apex/echosign_dev1__AgreementTemplateProcess and can pass many Adobe Sign parameters. In this example, I will only pass the agreement template id and the related record id as I don’t want the end user to choose these. My example also uses an Opportunity record but it could be any record in Salesforce that works Adobe Sign.

The first step is to create a visualforce page that sits in between the button and the contract signing page. In this page, I use the Opportunity standard controller and an extension. I used a hidden field so the extension does not have to query the Opportunity.
Code for the Visualforce Page:

[sourcecode language=”plain”]
<apex:page StandardController="Opportunity" Extensions="DataCheckExt" Action=" {!esignRedirect}" tabStyle="Opportunity">

<apex:form >

<apex:pageMessages ></apex:pageMessages>

<apex:commandButton action="{!opportunityRedirect}" value="Back to Opportunity" id="theButton" rendered="{!dataNeeded}" />

<apex:outputField value="{!Opportunity.Required_Data_Entered__c}" rendered="false"/>




I then created a boolean formula field on the Opportunity which returns true if all of the required data is populated. I check data from the Account and Opportunity. If you have more complex requirements, you could also do this validation the apex extension but the formula met my requirements and I wanted to keep it as simple as possible. I validate just four fields here but you can add whatever you need until you hit the formula field size limit. If this happens, you may need to move the logic to the apex extension.
Formula field on the Opportunity object which returns a Boolean:

[sourcecode language=”plain”]

NOT(ISBLANK( Account.Name)),


I then use this formula field to decide if the user can send the contract or not. The code below either send the user to the contract sending page or display an error message to let them know that the required data has not been entered on the Account/Opportunity.

[sourcecode language=”plain”]

public with Sharing class DataCheckExt{

// Opportunity that is being signed
public Opportunity opp;
// Standard Controller that we are extending
ApexPages.StandardController stdController;
// Do we have all the data needed
public boolean dataNeeded {get;set;}

public DataCheckExt (ApexPages.StandardController controller) {

stdController = controller;
opp = (Opportunity) controller.getRecord()
dataNeeded = false;

public PageReference esignRedirect() {

PageReference newPage;


newPage = new PageReference(‘/apex/echosign_dev1__AgreementTemplateProcess’);
newPage.getParameters().put(‘templateId’, opp.Agreement_ID__c);



newPage = null;
dataNeeded = true;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,’Error – Required Contract Data is Missing ‘));


return newPage;


// Redirect back to the Opportunity if necessary
public PageReference opportunityRedirect(){

PageReference newpage = stdController.view();

return newpage;




I have the agreement id in here as I don’t want users to select this and I have formula logic on the Opportunity to determine which agreement template should be used (Note: Agreement Template is the object Adobe Sign/Echosign uses to store the contract with it details and data). There are other parameters that could be added here but these are the key ones for me.

When the user clicks the Sign Contract button and the required data has not been entered, they get the apex error message dialog with the message I have chosen. This could be further extended by adding the data that is missing to the formula instead of returning a boolean to give a more specific error message. The error message could also be stored in a custom label for further flexibility including translations into different languages.

See the full code below on github:

Leave a Reply

Your email address will not be published. Required fields are marked *