You need to sign in to do that
Don't have an account?
Malakondaiah
How to write the test class for below trigger?
Hi All,
i Have written the test class for below trigger, i have inserted the lead object records but i am unable to cover the if loop condition.
Please could you guide me.
trigger priceCalcLead on Lead (before Insert, before Update)
{
Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'test' and SobjectType='Lead'].Id;
for(Lead led : Trigger.new)
{
if(led.RecordTypeId == recordTypeId){
if(led.Age__c >= 0 && led.Age__c <= 20){
Decimal cost = 45.20 ;
led.currencyfield__c = cost; // currency field
led.picklistfield1__c = 'pick1';
}
else if(led.Age__c >=21 && led.Age__c <=65) {
Decimal cost2 = 49.20;
led.currencyfield__c = cost2;
led.picklistfield1__c = 'test2';
}
else if(led.Age__c >=66 && led.Age__c <=100) {
Decimal cost3 = 65.00;
led.currencyfield__c = cost3;
led.picklistfield1__c = 'test2';
}
else {
Decimal cost4 =Null;
led.currencyfield__c = cost4;
led.picklistfield1__c = 'test2';
}
}
}
i Have written the test class for below trigger, i have inserted the lead object records but i am unable to cover the if loop condition.
Please could you guide me.
trigger priceCalcLead on Lead (before Insert, before Update)
{
Id recordTypeId = [Select Id From RecordType Where DeveloperName = 'test' and SobjectType='Lead'].Id;
for(Lead led : Trigger.new)
{
if(led.RecordTypeId == recordTypeId){
if(led.Age__c >= 0 && led.Age__c <= 20){
Decimal cost = 45.20 ;
led.currencyfield__c = cost; // currency field
led.picklistfield1__c = 'pick1';
}
else if(led.Age__c >=21 && led.Age__c <=65) {
Decimal cost2 = 49.20;
led.currencyfield__c = cost2;
led.picklistfield1__c = 'test2';
}
else if(led.Age__c >=66 && led.Age__c <=100) {
Decimal cost3 = 65.00;
led.currencyfield__c = cost3;
led.picklistfield1__c = 'test2';
}
else {
Decimal cost4 =Null;
led.currencyfield__c = cost4;
led.picklistfield1__c = 'test2';
}
}
}
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com