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
Amit Visapurkar 5Amit Visapurkar 5 

Trigger for docusign object

I have a trigger on dsfs__DocuSign_Status__c object which updates the status field on case object.  The trigger is firing when i use the send with docusign from another object. i want to know how to make sure that trigger fires only for case and not for any other object.

Below is the trigger

trigger signatureStatus on dsfs__DocuSign_Status__c (after insert,after update) {

Case t=new Case();

    for(dsfs__DocuSign_Status__c d:Trigger.New){
    
        if(d.Id!=null){
        
            if(stoprecurssion.runonce()){
            
                d=[SELECT Id,dsfs__Case__r.Signature_Required__c,dsfs__Case__r.Id,dsfs__Case__r.Status,dsfs__Envelope_Status__c FROM dsfs__DocuSign_Status__c WHERE Id=:Trigger.New];
            
                String e=d.dsfs__Case__r.Id;
            
                t=[SELECT ID,Signature_Required__c,Customer_Signature_Status__c,Status FROM CASE WHERE Id=:e];     
                                     
                if(t.Signature_Required__c==true){
                 
                     t.Customer_Signature_Status__c=d.dsfs__Envelope_Status__c;
                     
                update t; 
                 
                 }
            }

        }

    }

}

It's urgent
Siddharth ManiSiddharth Mani
Since your trigger is on dsfs__DocuSign_Status__c object, it will always fire when a insert/update is being done on it. So basically you cant bypass the trigger. However what you can do is have a condition in the trigger initially which would check for valid Case ID's before executing the rest of the code and if there are none then bypass the code.
Also on a side note - you seem to have multilpe queries inside a for loop which is not a recommended practice. You may need to bulkify your code a bit!
Amit Visapurkar 5Amit Visapurkar 5
Can you please help me with the condition to check the valid case Id.
Siddharth ManiSiddharth Mani
Havent tried it, but this might work:
1. Put this query at the begining of the trigger:
 
List<dsfs__DocuSign_Status__c> docsignList = [SELECT Id,dsfs__Case__r.Signature_Required__c,dsfs__Case__r.Id,dsfs__Case__r.Status,dsfs__Envelope_Status__c FROM dsfs__DocuSign_Status__c WHERE Id=:Trigger.New AND dsfs__Case__r.Id!=NUll];
This is assuming that your "dsfs__Case__r.Id" field stores the Id value of the Case record. If not, substitute that field accordingly which does so.

2. Put the rest of the logic you want to use under the condition that this list is not empty:
if(docsignList.size() > 0) {
--Rest of the trigger logic here--
}