DocuSign for Salesforce - Setting up triggers for individual recipients

255 views Asked by At

Is it possible to create a trigger on the ‘dsfs__DocuSign_Recipient_Status__c’ object? Use case: Contract goes to two people a) Client b) Sales Manager Events like updating opportunity stage, etc. should kick in as soon as the client signs, even though the envelope is not complete. I know we can do trigger events on 'Delivered', 'Sent' ,etc. on the DocuSign Status object but recipient-level variables (Recipient Status, Routing Order, etc.) are only available in the Recipient Status object.

I initially tried with two conditions (Recipient Status && Routing Order), then tried a simple one to test with just the Recipient Status. The trigger gets published but does not change the opp stage as intended - code below

trigger ClientSign on dsfs__DocuSign_Recipient_Status__c (after insert, after update) {

try
 {
    system.debug('In trigger');
    dsfs__DocuSign_Recipient_Status__c dssNew = Trigger.new[0];  
    dsfs__DocuSign_Recipient_Status__c dssOld = null; 
    if (!System.Trigger.isInsert) dssOld = Trigger.old[0];
    if (System.Trigger.isInsert || dssOld.dsfs__Recipient_Status__c != dssNew.dsfs__Recipient_Status__c)
    {
        if (dssNew.dsfs__DocuSign_Routing_Order__c == 1 && dssNew.dsfs__Recipient_Status__c == 'Completed')
        {
           Opportunity o = [select StageName from Opportunity where id=:dssNew.Opportunity__c];
           if (o != null)
           {
             o.StageName = 'Value Proposition';
             upsert o;
           }
        }
    }
}
catch (Exception ex)
{}
}
1

There are 1 answers

0
Geofferyp On

Yes triggers work on the dsfs__DocuSign_Recipient_Status__c object. I think your issue is with the Opportunity__c. That is not a default field on the dsfs__DocuSign_Recipient_Status__c object, so there must be something wrong there. I tested below code based on your trigger with a hard coded Opportunity. Result I updated the StageName from 'Needs Analysis' to 'Value Proposition'.

   trigger ClientSign  on dsfs__DocuSign_Recipient_Status__c (after insert, after update) 
    {
    try
     {
        system.debug('In trigger');
        dsfs__DocuSign_Recipient_Status__c dssNew = Trigger.new[0];  
        dsfs__DocuSign_Recipient_Status__c dssOld = null; 
        if (!System.Trigger.isInsert) dssOld = Trigger.old[0];
        if (System.Trigger.isInsert || dssOld.dsfs__Recipient_Status__c != dssNew.dsfs__Recipient_Status__c)
        {
            if (dssNew.dsfs__DocuSign_Routing_Order__c == 1 && dssNew.dsfs__Recipient_Status__c == 'Completed')
            {
                Id myId = Id.valueOf('006f4000004IfWQAA0');
                Opportunity o = [SELECT Name, StageName FROM Opportunity WHERE id = :myId Limit 1];
                system.debug(o.Name);
                system.debug(o.StageName);
                o.StageName = 'Value Proposition';
                upsert o;
            }
        }
    }
    catch (Exception ex)
    {}
    }