function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sflearnsflearn 

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 )

JPClark3JPClark3

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
{
	get
	{
	if (FromLineItemUpdate == null) FromLineItemUpdate = false;
	return FromLineItemUpdate;
	}
	set;
}

 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.