You need to sign in to do that
Don't have an account?
Update is failing in the test coverage
Class:
Map<String,Integer> ScoreMap = new Map<String,Integer>{'A4'=>7,'B4'=>7,'C4'=>5,'D4'=>4,'E4'=>4,'A3'=>8,'B3'=>7,'C3'=>6,'D3'=>5,'E3'=>5,};
if(sOperation== 'sUpdate')
{
Contact oldC = OldConTriggerMap.get(c.Id);
if((oldC.Score_OL__c!= c.Score_OL__c ||
oldC.Score_MC__c!= c.Score_MC__c ||
oldC.Score_PF__c!= c.Score_PF__c&& ScoreMap.ContainsKey(c.Score_MC__c))
)
{
c.Score_OL__c = ScoreMap.get(c.Score_MC__c);
}
}
Test Class:
//Create a new account
Account acc=new Account(Name='Account37',Phone='1142234334',Type = 'Prospect',
Score_PF__C = 'B',
);
insert acc;
//Create new contact
Contact con = new Contact();
con.LastName='ContactCS6737';
con.AccountId=acc.Id;
con.Score_MC__c = 'B1';
insert con;
con.Score_MC__c='B3';
update con;
Contact updatedCon=[SELECT Id,LastName,Score_MC__c from Contact WHERE Id=:con.Id];
System.assertEquals('B3', con.Score_MC__c);
None of the lines are covered.
Regards,
Ajay
If code is not covered then you might wanna check your IF condition. If error then there might be different problem
No errors, Code is not getting covered.
All the below lines are not covered:
Contact oldC = OldConTriggerMap.get(c.Id);
if((oldC.Score_OL__c!= c.Score_OL__c ||
oldC.Score_MC__c!= c.Score_MC__c ||
oldC.Score_PF__c!= c.Score_PF__c&& ScoreMap.ContainsKey(c.Score_MC__c))
)
{
c.Score_OL__c = ScoreMap.get(c.Score_MC__c);
}
Regards,
Ajay
if( sOperation == 'sUpdate')
is the problem
Regards,
Ajay
public static void OverallLeadScoreUpdate (Map<Id,Contact> OldConTriggerMap , List<Contact> NewConTriggerList, string sOperation)
How do I set that as true?
Do I need to call actual method into my test class?
Reagrds,
Ajay
Finally I could figured out the issue. I have the recursive flag in my trigger. That is stopping to fire the update for some reason. If I remove that recursive variable, then the test class is covering 100%. Can you please look into this and let me know why this recusrive causing the issue?
This is how I have the trigger:
trigger ContactTrigger on Contact (before insert, before update, after delete, after insert , after update, after undelete) {
if(Trigger.isAfter){
if(Trigger.isInsert || Trigger.isUnDelete){
SomeClass.SomeMethod(Trigger.new,Trigger.oldMap,'sinsert');
}
if(Trigger.isUpdate ){
SomeClass.SomeMethod(Trigger.new,Trigger.oldMap,'sUpdate');
}
if(Trigger.isDelete){
SomeClass.SomeMethod(Trigger.new,Trigger.oldMap,'sDelete');
}
if(Trigger.isInsert){
SomeClass.SomeMethod(Trigger.new,Trigger.oldMap,'sinsert');
}
MyUtil.setAlreadyModified();
}
if(Trigger.isBefore){
if (!MyUtil.isAlreadyModified())
{
if(Trigger.isInsert){
SomeClass.SomeMethod(Trigger.new,Trigger.oldMap,'sinsert');
}
if(Trigger.isUpdate){
SomeClass.SomeMethod(Trigger.new,Trigger.oldMap,'sUpdate');
}
}
}
}
My Utili Class: for Recusrive variable
public class MyUtil{
private static boolean alreadyModified = false;
public static boolean isAlreadyModified() {
return alreadyModified;
}
public static void setAlreadyModified() {
alreadyModified = true;
}
}
Regards,
Ajay