You need to sign in to do that
Don't have an account?
The new Learner
How to cover If condition in test class
Hi Experts,
I am struggling to cover the below if condition line( if(minutes <60)) in the test class can anyone help me out, please?
I am struggling to cover the below if condition line( if(minutes <60)) in the test class can anyone help me out, please?
for(campaignmember cm:listcamps) { Long customFieldLong = cm.CreatedDate.getTime(); Long dt2Long = DateTime.now().getTime(); Long milliSeconds = dt2Long - customFieldLong; Long seconds = milliSeconds / 1000; Long minutes = seconds / 60; if(cm.status=='Form' || cm.status=='submit') { if(minutes<60) { cammemleadId.add(cm.leadId); }
Thanks for providing the Code,
i have replicated the code in my personal Org and based on my debugging the issue is not with the if condition in minute , the code is not even reaching till the if condition.
The logic was not satisfied in the above if condition it self (i.E : if(cm.status=='Form' || cm.status=='submit') )
On further debugging : the issue was even tough we are trying to place values in picklist value of status : since we are using OOTB status field the the picklist value of form is not getting stamped and , the default picklist value of sent is getting stamped in my case.
Debug SS:
Campaign member status field values :
Can you kindly provide the picklist values for your campain member object : status field
FYI , i changed the condition in if clause to status=sent and the code coverage reached 100%.
Thank you ,
Karthik
All Answers
Based on your code , you are validating and capturing only the data modified in last hour. So any test data created VIA test class must be eligible for your class . could you please share the query for listcamps and also the test class you used .
When i tried to execute your logic it covered for me inside the if condition . The reason being in test class i created the account so the createddate will be latest.
Test class :
Thank you,
karthik
Hi
Refer these examples :-
https://developer.salesforce.com/forums/?id=906F000000091SnIAI
https://developer.salesforce.com/forums/?id=9060G0000005NN9QAM
Kindly mark it as the best answer if it works for you.
Thanks & Regards,
Priya Ranjan
Thanks for providing the Code,
i have replicated the code in my personal Org and based on my debugging the issue is not with the if condition in minute , the code is not even reaching till the if condition.
The logic was not satisfied in the above if condition it self (i.E : if(cm.status=='Form' || cm.status=='submit') )
On further debugging : the issue was even tough we are trying to place values in picklist value of status : since we are using OOTB status field the the picklist value of form is not getting stamped and , the default picklist value of sent is getting stamped in my case.
Debug SS:
Campaign member status field values :
Can you kindly provide the picklist values for your campain member object : status field
FYI , i changed the condition in if clause to status=sent and the code coverage reached 100%.
Thank you ,
Karthik
Those are the values means ? can you please provide the screenshot for what values are present in ur org?.
and also add the in line you class after long minutes and kindly provide the value its printed after running the test class.
Thanks,
Karthik
your absolutely right , for that I have inserted the below the record and then code coverage got improved. and kudos for ur efforts