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
Andrew marshal 3Andrew marshal 3 

help me to create this trigger

If the Opportunity Product has a Status of "Shipped" , it checks the Category of the related Product and sets the Final Price based on the following criteria:

If the Category is "Category A", the Final Price is set to 80% of the Unit Price.
If the Category is "Category B", the Final Price is set to 90% of the Unit Price.
If the Category is not "Category A" or "Category B", the Final Price is set to the Unit Price.

If the Opportunity Product does not have a Status of "Shipped", the formula returns the existing value of the Final Price field.
Best Answer chosen by Andrew marshal 3
SubratSubrat (Salesforce Developers) 
Hello Andrew ,

Please try with below code and let me know if you face in difficulty :
trigger UpdateFinalPrice on OpportunityLineItem (before update) {
  for (OpportunityLineItem oli : Trigger.new) {
    if (oli.Status == 'Shipped') {
      Product2 prod = [SELECT Category FROM Product2 WHERE Id = :oli.Product2Id];
      if (prod.Category == 'Category A') {
        oli.Final_Price__c = oli.UnitPrice * 0.8;
      } else if (prod.Category == 'Category B') {
        oli.Final_Price__c = oli.UnitPrice * 0.9;
      } else {
        oli.Final_Price__c = oli.UnitPrice;
      }
    }
  }
}
Hope it helps !
Thank you.