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
amine7amine7 

Test a Trigger need Help

Hello everybody , I really nead some help on how to create a test class in order to bring a Trigger over the prodution instance..

Here is it :


trigger monTrigger on Dossier_P_re__c(before update){
  
    List<Case> op= new  List<Case>();
   
    Set<Id> ChampReq = new Set<Id>();
   
    for(Dossier_P_re__c dos : Trigger.new)
    {
            ChampReq.add(dos.Id); // L'Id de l'objet Dossier_P_re__c dans le ticket Principal    
    }
                
    if(System.Trigger.isUpdate)
    {
        try
        {
        op=[select Dossier_P_re__c, Status,IsClosed from Case where Dossier_P_re__c In: ChampReq];
     
        }
        catch(Exception e){ System.debug('Exception' + e);
        }
    
         for(Dossier_P_re__c dosDeux : Trigger.new)
         {
            if(dosDeux.Statut__c =='Clos')
            {
                    for(Case cas : op)
                    {
                     cas.Status='Clos';
                     update(cas);
                                         
                    }    
                   
            }
               
       } 
     }                 
   
}

 

Really  need some help !  Thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
ashish raiashish rai

Hello,

   Your test method should be like this:

 

@isTest
private class monTrigger_TESTS
{
    static testMethod void mytestclass()

{

List<Case> op= new  List<Case>();

 Set<Id> ChampReq = new Set<Id>();

Dossier_P_re__c xyz=new Dossier_P_re__c( name='asssss',other mandatory fields);

insert xyz;

      contact con=new contact(firstname='testing',lastname='123');

insert con;

   Case c = new Case(Subject = 'Test Case with Entitlement ', EntitlementId = entlId,      ContactId= con.id);

insert c;

xyz..Statut__c =='Clos';

update xyz;

}

}

 

Think this will help you to cover the trigger.

All Answers

ashish raiashish rai

Hello,

   Your test method should be like this:

 

@isTest
private class monTrigger_TESTS
{
    static testMethod void mytestclass()

{

List<Case> op= new  List<Case>();

 Set<Id> ChampReq = new Set<Id>();

Dossier_P_re__c xyz=new Dossier_P_re__c( name='asssss',other mandatory fields);

insert xyz;

      contact con=new contact(firstname='testing',lastname='123');

insert con;

   Case c = new Case(Subject = 'Test Case with Entitlement ', EntitlementId = entlId,      ContactId= con.id);

insert c;

xyz..Statut__c =='Clos';

update xyz;

}

}

 

Think this will help you to cover the trigger.

This was selected as the best answer
amine7amine7

Thanks a lot ! have a nice day !