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
kevin.chileskevin.chiles 

Trigger to roll up information from Docusign Status to Change Opp Status

Howdy Folks!  I am trying to write a trigger that will work like a roll up summary field.  I have to run this through a trigger as I cannot create a master detail relationship with a managed custom object.  This is using docusign.

 

The use case is this.  When a doc is marked as completed in the custom object Docusign status (dsfs__DocuSign_Status__c).  I need to get a count of items either completed or Denied and use that data to manage the Opportunity stage.

 

If status =complete, stage = Closed Won

if Status=Denied, Stage = Closed Lost

 

Has anyone run into this issue?!  I cannot believe I am the first one to need this automation.  Thanks folks!

Best Answer chosen by Admin (Salesforce Developers) 
Sri549Sri549

Hi Kevin,

As per my understanding of your scenario

Thsi is trhe Sample Trigger

trigger Status on Docusign__c(After Insert,After Update) {

    Map<ID,String> mapoppid=new Map<ID,String>();
    List<ID> OppIDs = new List<ID>();
               
  if(Trigger.isInsert || Trigger.isUpdate)
    for(Docusign__c ds:Trigger.new)      
    {
    system.debug('###########'+ds.Status__c);     
       if(ds.Status__c=='complete'){
       mapoppid.put(ds.Opportunity__c,'Closed Won');
    }
   else if(ds.Status__c=='Denied'){
        mapoppid.put(ds.Opportunity__c,'Closed Lost');
    }
    
    List<Opportunity> Updateopp=[SELECT Id,StageName FROM Opportunity WHERE Id IN:mapoppid.keyset()];
 
     for(Opportunity opp:Updateopp)
     {
      Opp.StageName=mapoppid.get(Opp.Id);
      system.debug('###########'+Opp.StageName);
     }   
    Update Updateopp;
    }
            }

 

You can make modification as per your requirement ...

Thanks

Srinivas

 

 

 

All Answers

AmitdAmitd

Hi,

 

your question is not clear.

for e.g lets say i have 5 records of dsfs__DocuSign_Status__c and out of 5 only status of one record is complete, in this case should we set the status of opportunity to Closed Won or is there any specific number of record with complete status.

Sri549Sri549

Hi Kevin,

As per my understanding of your scenario

Thsi is trhe Sample Trigger

trigger Status on Docusign__c(After Insert,After Update) {

    Map<ID,String> mapoppid=new Map<ID,String>();
    List<ID> OppIDs = new List<ID>();
               
  if(Trigger.isInsert || Trigger.isUpdate)
    for(Docusign__c ds:Trigger.new)      
    {
    system.debug('###########'+ds.Status__c);     
       if(ds.Status__c=='complete'){
       mapoppid.put(ds.Opportunity__c,'Closed Won');
    }
   else if(ds.Status__c=='Denied'){
        mapoppid.put(ds.Opportunity__c,'Closed Lost');
    }
    
    List<Opportunity> Updateopp=[SELECT Id,StageName FROM Opportunity WHERE Id IN:mapoppid.keyset()];
 
     for(Opportunity opp:Updateopp)
     {
      Opp.StageName=mapoppid.get(Opp.Id);
      system.debug('###########'+Opp.StageName);
     }   
    Update Updateopp;
    }
            }

 

You can make modification as per your requirement ...

Thanks

Srinivas

 

 

 

This was selected as the best answer
kevin.chileskevin.chiles

Thank you very much!  This was just what I was looking for!  Currently I am writing it as 2 triggers but this should consolidate that and I would only have to write one Test class as opposed to 2 of them.  Thank you very much!  Just for fun, would you happen to have an example of what my class should look like?  I always get this far and then fail in deployment as I am not very good at putting the test classes together.  Thank you Srinivas!

amit pandey 9amit pandey 9
Hi,  please any one help me . i am trying to update opportunity stageName field when client signed document .but i am getting problem . it is upated but it always updated with the value 'completed' and i wants 'Closed Won' at the place of 'Completed.'  

i make a trigger for this but i am not getting proper out comes.

this is my trigger please help me to over come this problem.........

trigger checkStage on dsfs__DocuSign_Status__c (After Insert,After Update) {
       List<Id> oppIds = new List<Id>();
       for(dsfs__DocuSign_Status__c dc:trigger.new){
      if(dc.dsfs__Envelope_Status__c =='complete'){
       oppIds.add(dc.dsfs__Opportunity__c);    
       }
    }
      
    List<Opportunity> oppList = [select StageName from Opportunity where id in:oppIds];
          List<Opportunity> oppListnew = new List<Opportunity>();
          for(Opportunity op : oppList){
       op.StageName='Closed Won';
       oppListnew.add(op);
         }
         update oppListnew;
    }