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
Geoffrey LambGeoffrey Lamb 

EchoSign Trigger: Send Contract onCreate of record

I recently installed EchoSign for Salesforce and finally have things up and running with my users being able to send documents with a single click. Now, I need to take it one step further and figure out a way to send a contract without user interaction, at the time a record (Lead) is created. 

Adobe talks about workflows in thier marketing but offers no obvious direction as to how to go about setting them up. As far as I can tell, this is not something which is a part of standard workflows so it sounds like I'm going to have to write another trigger??

Well, I've written a few triggers in the past but I am far from an expert. I can do it, I just need something to show me the way... I would appreciate any links or code snippets that anyone could offer. I'm sort of lost at this point and Adobe help & support is basically non-existent.

Thank you!

PS: I know how to find the basic Salesforce help guides on Apex Triggers - I need something specific to EchoSign. Thanks!
Ali WhiteAli White
Hi Geoffrey,

I just came across your old question. Did you ever find a solution to this without using Triggers?

Funnily enough when I spoke to Adobe earlier in the year I brought up the exact same point you did about it being mentioned in their marketing (which was my main reason for purchasing) yet it doesn't actually allow this.  

I've also been trying to get a solution without a trigger (as I can't write code), and I was told by Salesforce to trial the new Lighning beta - but also struggling to make it work there?

Cheers,

Ali
Geoffrey LambGeoffrey Lamb
Unfortunately, code was the only way to go for me. I have to initiate/send these using apex triggers and classes. The good news is that, as code goes, it's actually pretty easy. You just have to call their load method and pass the Agreement Template Id, as well as the associated record Id (such as your Lead or Account).

Unfortunately, I do not know how to initiate an Echosign agreement without using code. The line which initiates the package is below, it could be dropped into a basic insert or update trigger pretty easily.

echosign_dev1.AgreementTemplateService.load( [AgreementTemplateId] , [RecordId] )

PS: Don't let the code intimidate you! I didn't know anything this time last year and now, I can do almost anything I need. It wasn't easy but definitely not impossible - I just read the forums and troubleshot everything until it worked. Knowing some basic triggers is super helpful for stuff like this.
Mark OlingerMark Olinger
Has anyone else had success doing this?   I've tried the code above in a trigger but it does not successfully send the agreement.  It creates the Agreement, but it does not get sent.  In the Document Cloud Actions section on the Agreement, it say 'Attempt to De-Reference Null Object'.   When I manually click on the 'Send For SIgnature' button, it sends no problem without further interaction.  
Mark OlingerMark Olinger
Also, BTW What version of EchoSign were you working with where you were able to get this working?

Thanks!
Geoffrey LambGeoffrey Lamb
Hi Mark,

I can't be sure without seeing all of the trigger's code and/or the debugging script - but it sounds like the method above is actually working for you, otherwise, it seems like the agreement itself would have some sort of error (not related to sending) or not be created at all??

The piece of the puzzle that makes the agreement send, if I remember correctly, is in the template and not the apex code. I think the code just creates the template, like the send button... so it's odd that the send button works perfectly while the code does not.

Some random ideas:
  • Did you add a mapping to the template, so that the word "send" would be inserted into the On_Load_Action__c field at agreement creation?
  • Did you add the recipients in the agreement template?
    • Do they have a valid email address? (seems easy, but screws with us all the time)
  • Is your send agreement button taking any actions or doing anything that is not connected with creation of the template?
    • If it's doing anything else programmatically then perhaps that needs to be replicated in your trigger, prior to invoking the AgreementTemplateService.load() method??
That’s what i could come up with for now. If none of this is the issue, I may be able to help more tomorrow with the trigger code or the debugging logs. Knowing what exactly is null would be really helpful and that should hopefully be clear upon review of the logs and code. Also, having a copy of the send agreement javascript may be useful too. I'd like to know what precisely is different, between your broken trigger and the script in your working button.

Good luck!
Geoffrey LambGeoffrey Lamb
We have Enterprise Salesforce with Enterprise Echosign. I don't know the current version number but assume that is updated by Adobe automatically?? Initially, we had a working Send button (like you) but no idea how to get it into a workflow or trigger. As soon as I found that line of code to fire the template load method - it worked perfectly and has ever since. By the way, my above answer assumes that you know all about the details of trigger development or otherwise, I'd probably have started with that  :-)
 
Mark OlingerMark Olinger
Thanks Geoff  for the quick reponse!

1)  We do have a Merge Mapping defined in the Template, but not a Data Mapping, but thought that was only for bringing data fields back into SF.
2)  Yes we have Recipient defined to pull from email field on the Account
3)  There shoudl be nothing special about the button, we are using the standard Send For Signature echosign button.  URL is - /apex/echosign_dev1__AgreementTemplateProcess?masterId={!Account.Id}

The trigger code is very basic, but attached here (just the important part).  Yes I've written a lot of triggers before.

trigger EchoSignSendAgreement on Account (after insert) {
  List<Account> accts = Trigger.new;
      echosign_dev1__Agreement_Template__c tem= [Select Id from echosign_dev1__Agreement_Template__c Where Name='Merchant Agreement Consumer Goods'];
        
      for (Account acct : accts) {
            SendAgreement_Methods.sendAgreement(tem.Id , acct.id );
       }   
    }

public class SendAgreement_Methods {
  
    @future (callout=true)
    public static void sendAgreement(Id temId, Id acctId) {
        try {
            System.debug('Calling AgreementTemplateService.load: ' + temid + ' - ' + acctid);
          echosign_dev1.AgreementTemplateService.load( temid , acctid );
            
        } catch (Exception E) { System.debug('Exception: ' + e.getStackTraceString());}       
    }

}


And I've looked at the logs, and there are no errors at all.  I compared the logs with what happens when you click on the button, adn they are same, up until a certain point, when the logs for the trigger just stop and the logs when clicking on the button just continue.  Hard to tell exactly what is being executed though.

 
Nidhi GuptaNidhi Gupta
Hi,
We are using the trigger based approach and calling echosign_dev1.AgreementTemplateService.load( templatedId , RecordId ). Hope you have set "Auto Send" checkbox on the agreement template. And the emails ids are correctly getting populated when an agreement is generated.

Thanks
Nidhi
 
Melissa Shook 16Melissa Shook 16
Would you give me an example of the trigger? I am new to this and I am still having trouble.
praveen kumar 407praveen kumar 407
Hi Geoffrey Lamb, 
It will be great if you post your code here. 

Thanks,
Praveen K S
Angel BrownAngel Brown
As anyone been able to figure this out declaratively (using for example Flows) in Salesforce? The Adobe documents do not give a clear guide on how to do this, the documents pretty much state it can be accomplished.