+ Start a Discussion
Amit Visapurkar 5Amit Visapurkar 5 

Please help with the test Class for the trigger

Please help with the test class for the following 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(d.dsfs__Case__r.Signature_Required__c==true && d.dsfs__Envelope_Status__c=='Completed'){                

                t.status='Closed';
                
                t.Customer_Signature_Status__c=d.dsfs__Envelope_Status__c;
                     
                update t;                 
        
           }
           
           else{
           
                  t.status=d.dsfs__Case__r.Status;
                  
                  update t;                
           
           }
            
            }
            
        
        }
    
    
    }

}

It's urgent
Best Answer chosen by Amit Visapurkar 5
JethaJetha
@isTest
private class myTestClass()
{
	@isTest static void myTestMethod()
	{
		Case testCase = new Case();
		//Initialise your case object here with all required value
		insert testCase;
		
		
		dsfs__DocuSign_Status__c ds = new dsfs__DocuSign_Status__c();
		ds.dsfs__Case__c = testCase.Id;
		//assign other required value
		insert ds;
        stoprecurssion.runonce();

	}
	
	@isTest static void myTestMethod2()
	{
		stoprecurssion.runonce();

	}
}

It is going to through error because your case doesn't have all the required field. Please modify your triggert accordingly

All Answers

JethaJetha
@isTest
private class myTestClass()
{
	@isTest static void myTestMethod()
	{
		Case testCase = new Case();
		//Initialise your case object here with all required value
		insert testCase;
		
		
		dsfs__DocuSign_Status__c ds = new dsfs__DocuSign_Status__c();
		ds.dsfs__Case__c = testCase.Id;
		//assign other required value
		insert ds;
	}
}

Try this and let me know if any line is not getting covered.
Amit Visapurkar 5Amit Visapurkar 5
public class stoprecurssion{
public static boolean flag=true;
public static boolean runonce(){
if(flag){
   flag=false;
  }
else {
   return flag;
  }
   return true;
 }
}

calling this method from trigger. 

return flag is not getting covered
JethaJetha
That is actaully a good news for you that your trigger is not a recurssive trigger.

And by looking at your code, I don't think this code can ever trap into recurssive situation.

Do you have any trigger on case object in which you are performing DML operation  on dsfs__DocuSign_Status__c  object.

if not you can remove stoprecurssion.runonce() from line ten.

you can also cover this class by calling it externally like below:
 
@isTest
private class myTestClass()
{
	@isTest static void myTestMethod()
	{
		Case testCase = new Case();
		//Initialise your case object here with all required value
		insert testCase;
		
		
		dsfs__DocuSign_Status__c ds = new dsfs__DocuSign_Status__c();
		ds.dsfs__Case__c = testCase.Id;
		//assign other required value
		insert ds;
                stoprecurssion.runonce();

	}
}
Don't forget to mark it best answer if it resolve your issue.
Amit Visapurkar 5Amit Visapurkar 5
  else{
           
                  t.status=d.dsfs__Case__r.Status;
                  
                  update t;                
           
           }

the else part is also not getting covered
JethaJetha
@isTest
private class myTestClass()
{
	@isTest static void myTestMethod()
	{
		Case testCase = new Case();
		//Initialise your case object here with all required value
		insert testCase;
		
		
		dsfs__DocuSign_Status__c ds = new dsfs__DocuSign_Status__c();
		ds.dsfs__Case__c = testCase.Id;
		//assign other required value
		insert ds;
        stoprecurssion.runonce();

	}
	
	@isTest static void myTestMethod2()
	{
		stoprecurssion.runonce();

	}
}

It is going to through error because your case doesn't have all the required field. Please modify your triggert accordingly
This was selected as the best answer
Amit Visapurkar 5Amit Visapurkar 5
Thank you very much