You need to sign in to do that
Don't have an account?

Test Class for Trigger.
Hi,
This is my trigger and how to write test class for this trigger.
trigger OppProductDelete on OpportunityLineItem (before delete){
Id sysAdminId = [Select Id, Name from Profile where id = '00e90000001qXNbAAM' LIMIT 1].Id;
for (OpportunityLineItem oppProd : trigger.old){
if(UserInfo.getProfileId() ==sysAdminId)
oppProd.addError('This Opp Product may not be deleted');}
}
thanks.
This is my trigger and how to write test class for this trigger.
trigger OppProductDelete on OpportunityLineItem (before delete){
Id sysAdminId = [Select Id, Name from Profile where id = '00e90000001qXNbAAM' LIMIT 1].Id;
for (OpportunityLineItem oppProd : trigger.old){
if(UserInfo.getProfileId() ==sysAdminId)
oppProd.addError('This Opp Product may not be deleted');}
}
thanks.
1. Please do not hard code profile id to anywhere. User profile name instead of that.
2. To cover your trigger, you need to insert, opportunity, product, pricebook. Then finally delete it and assert the exception.
Find the modfied class and new test class, it will solve your problem.
Trigger
Test Class
All Answers
Have you tried any snippet of code that you can share?
You need to first insert an opportunity and then opportunity line item in your test class and then delete it.
1. Please do not hard code profile id to anywhere. User profile name instead of that.
2. To cover your trigger, you need to insert, opportunity, product, pricebook. Then finally delete it and assert the exception.
Find the modfied class and new test class, it will solve your problem.
Trigger
Test Class
Please use below code it will help you to solve your problem .
But only thing is that in each record level you have to give the mandatory fields as per your organisation .