You need to sign in to do that
Don't have an account?

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
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
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.
Thanks a lot ! have a nice day !