You need to sign in to do that
Don't have an account?
The new Learner
Trigger is not working , when the products are more than two
Hi Experts,
I have written a trigger, when the opportunity contain inactive product I need to throw an error, however, its working fine for one product, when it have more than one , when I am trying to delete it's not working its throwing an error by saying "select correct product"
can anyone help me out?
I have written a trigger, when the opportunity contain inactive product I need to throw an error, however, its working fine for one product, when it have more than one , when I am trying to delete it's not working its throwing an error by saying "select correct product"
can anyone help me out?
public static void products(Set<Id> oppIds, List<Opportunity> opplist) { List<OpportunityLineItem> opplineitems = [SELECT OpportunityId FROM OpportunityLineItem WHERE Product2.IsActive = false AND OpportunityId IN: OppIds]; Set<Id> opptyId = New Set<Id>(); for(OpportunityLineItem opplt:opplineitems) { opptyId.add(opplt.OpportunityId); } for (Opportunity opp :opplist) { if(opptyId.contains(opp.Id)) { opp.addError('select correct product'); } } }
Hi,
Try this below code.
Please mark it as the Best Answer If it helps you
Thank You
same error , not deleting
yes, your trigger is working fine. it gives error because you are firing on delete also.
If you want that error is not throw on delete event then remove trigger.delete functionality like below.
above trigger only work when you will update opportunity. delete will not effect on it.
let me know if it helps you and marking it as best Answer.
Thank you