You need to sign in to do that
Don't have an account?
Julie Curry
test class for prevent opportunity product delete trigger
I am an admin. I don't code but worked with the community and a salesforce support rep to create the below trigger for preventing opportunity products from being deleted. Now I need a test class to deploy it and I'm not sure how to create it. Can anyone help?
trigger PreventOpportunityProductDeletion on OpportunityLineItem (before delete) {
if(userinfo.getProfileId() != '00e60000001504CAAQ')
{
for(OpportunityLineItem oppli: trigger.old){
oppli.adderror('Opportunity Product can only be deleted by a System Administrator.');
}
}
}
trigger PreventOpportunityProductDeletion on OpportunityLineItem (before delete) {
if(userinfo.getProfileId() != '00e60000001504CAAQ')
{
for(OpportunityLineItem oppli: trigger.old){
oppli.adderror('Opportunity Product can only be deleted by a System Administrator.');
}
}
}
remove hardcoded profile Id
Test CLass
When I validate prior to deploying into production, is the error that I'm getting "System.DmlException: Delete failed. First exception on row 0 with id 00k1g0000081vIZAAY; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Only a system administrator can delete line items: []" expected??
I'm new to deploying triggers and classes and have not run into this error before. It's almost as if the validation error is a good thing as it seems that it's a result of the error that the trigger is generating when the test class tries to delete the opp line item that it has inserted. I don't want to deploy this as is becuase of this error but maybe it's ok??