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

Update Stage name from opportunity line item to opportunity

I have a field called Stage in opportunity product object and values are same as the opportunity stage.
An opportunity can have multiple line items.
In terms of logic, the stage on the Opportunity should be the lowest stage amongst stages of line item.
E.g.: If there are 3 line items with stages: 4, 5, 7 ( I am not using exact stage names for sake of simplicity) then stage value on the Opportunity should be 4.

Its kind of urgent.Please let me know how to do it.


As per your requirement description, I assume you want the opportunity stage to be set everytime a new Opportunity Line Item(OLI) is added.. To do this, follow the steps below
1. Create an after trigger on OLI
2. Get all the other OLI's related to the Parent opportunity based on Opportunityid field.
3. Declare a Set variable with string datatype and add all the stage names of the related OLI's
4. Use if else conditions to see if the set contains the stagename starting with the least stage name and ending with the highest. Within ifelse update the Opportunity stage.

Hope this helps.