You need to sign in to do that
Don't have an account?
System Admin 949
test trigger problem
Dear community,
below is the my trigger,iam facing some problem for creation of test class.how to create the testfactory for this trigger
trigger:
trigger CheckDefaultPlantContact on PlantContact__c (before insert,before update)
{
Set<String> contactTypeSet = new Set<String>();
Set<String> prodFamilySet = new Set<String>();
Map<String, PlantContact__c> productPlanMap = new Map<String, PlantContact__c>();
For(PlantContact__c p : Trigger.New)
{
If(p.TypeOfContact__c != null)
{
contactTypeSet.add(p.TypeOfContact__c);
}
If(p.ProductFamily__c != null)
{
prodFamilySet.add(p.ProductFamily__c);
}
}
For(PlantContact__c p :[SELECT Id, TypeOfContact__c,ProductFamily__c FROM PlantContact__c WHERE TypeOfContact__c =:contactTypeSet AND Default__c = TRUE AND ProductFamily__c =: prodFamilySet])
{
productPlanMap.put(p.TypeOfContact__c+'-'+p.ProductFamily__c, p);
}
For(PlantContact__c p : Trigger.New)
{
String keyChek = p.TypeOfContact__c+'-'+p.ProductFamily__c;
If(!productPlanMap.containsKey(keyChek))
{
IF(!p.Default__c)
{
p.name.addError('Please Mark as Default. There should be one default Contact for type '+ p.TypeOfContact__c);
}
}
IF(p.Default__c)
{
If(productPlanMap.containsKey(keyChek))
{
p.name.addError('One Product Family have only one Default for each '+ p.TypeOfContact__c +' type');
}
}
}
}
can any one provide hoew to create the test class for this.
thanks in advance
below is the my trigger,iam facing some problem for creation of test class.how to create the testfactory for this trigger
trigger:
trigger CheckDefaultPlantContact on PlantContact__c (before insert,before update)
{
Set<String> contactTypeSet = new Set<String>();
Set<String> prodFamilySet = new Set<String>();
Map<String, PlantContact__c> productPlanMap = new Map<String, PlantContact__c>();
For(PlantContact__c p : Trigger.New)
{
If(p.TypeOfContact__c != null)
{
contactTypeSet.add(p.TypeOfContact__c);
}
If(p.ProductFamily__c != null)
{
prodFamilySet.add(p.ProductFamily__c);
}
}
For(PlantContact__c p :[SELECT Id, TypeOfContact__c,ProductFamily__c FROM PlantContact__c WHERE TypeOfContact__c =:contactTypeSet AND Default__c = TRUE AND ProductFamily__c =: prodFamilySet])
{
productPlanMap.put(p.TypeOfContact__c+'-'+p.ProductFamily__c, p);
}
For(PlantContact__c p : Trigger.New)
{
String keyChek = p.TypeOfContact__c+'-'+p.ProductFamily__c;
If(!productPlanMap.containsKey(keyChek))
{
IF(!p.Default__c)
{
p.name.addError('Please Mark as Default. There should be one default Contact for type '+ p.TypeOfContact__c);
}
}
IF(p.Default__c)
{
If(productPlanMap.containsKey(keyChek))
{
p.name.addError('One Product Family have only one Default for each '+ p.TypeOfContact__c +' type');
}
}
}
}
can any one provide hoew to create the test class for this.
thanks in advance
Raj Vakati
Try this code .. add required field and
Raj Vakati
try this