You need to sign in to do that
Don't have an account?
pinky1
Trigger Test class, code coverage help
We have two custom fields on leads pardot hard bounced and pardot hard bounced cloned. if pardot hard bounced is true, we need to make pardot hard bounced cloned, if a lead updates a field on the record.
For this i have written Trigger and the code coverage is 0%. I want to deploy it to production. If i need to deploy need to write a test class and apex class. Can someone help me with this. I am new to coding.
below is the trigger i have written:
trigger UpdateLead on Lead (before update) {
for(Lead l: Trigger.new) {
If (l.pi__pardot_hard_bounced__c == true ){
l.Pardot_Hard_Bounce_Cloned__c = true;
}
else {
l.Pardot_Hard_Bounce_Cloned__c = False;
}
}
}
For this i have written Trigger and the code coverage is 0%. I want to deploy it to production. If i need to deploy need to write a test class and apex class. Can someone help me with this. I am new to coding.
below is the trigger i have written:
trigger UpdateLead on Lead (before update) {
for(Lead l: Trigger.new) {
If (l.pi__pardot_hard_bounced__c == true ){
l.Pardot_Hard_Bounce_Cloned__c = true;
}
else {
l.Pardot_Hard_Bounce_Cloned__c = False;
}
}
}
All Answers
Hey
Consider Test class as an automated way to test all the scenario which your code functionality can face.
In this case, You can write a test class and
- Create a Lead record in the test class.
- Update its field value(TestLead.pi__pardot_hard_bounced__c = true) between Test.Start() and Test.Stop().
- Add system assert to check Pardot_Hard_Bounce_Cloned__c value of your test lead.
To get 100% coverage, You will have to write methods on Test class which execute each line of your trigger code.You can use the developer console to check which line has been covered by your test class after test execution.
As a best practice to learn, I would suggest you read a bit about the test class and write it on your own.
Your problem is easy, It won't be difficult for you to write a test class code for this.
Thanks
Try the test class below
Hope this helps,
Thanks,
Sarvani
Thanks for helping me with the code