+ Start a Discussion

befor trigger

i have an opportunity before trigger that works great but how do i keep it from firing when a new opportunitylineitem is added? it keeps changing a field on the opportunity causing it the opportunity to fire also there are some rollup fields on the opportunity and i think that is also the issue 

Sfd developerSfd developer

You can't do this. opportunity before trigger fires only when you do dml on opportunity. But, you can achieve this by creating a trigger on opportunitylineitem and updates its assoicated opportunity record. (ie use after trigger )


This can sometimes happen when a workflow updates the opportunity record. 


Trigger Order of Execution


One method around this it to create a class with a public static property:

public static boolean FromLineItemUpdate
	if (FromLineItemUpdate == null) FromLineItemUpdate = false;
	return FromLineItemUpdate;

 Then Create a trigger for the OpportunityLineItem, Set this public property to true.


Finally, at the beginning your Opportunity trigger, check the value, and exit if it is true.