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
Roopa S 1Roopa S 1 

plz help me to write trigger

need to write trigger to calculate discount.
example- if the price is 100
after saving price should populate with 10% discount
 
mukesh guptamukesh gupta
Hi Roopa,

Please follow below code:-
 
trigger PriceUpdateTrigger on OpportunityLineItem(before insert) {

        for (OpportunityLineItem oli: Trigger.New){
            oli.sales_price__c =  oli.sales_price__c - (10/100)*oli.sales_price__c;
		}			
}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
Suraj Tripathi 47Suraj Tripathi 47
Hi Roopa,
Please use below code :- 

trigger PriceUpdateTrigger on Account (before insert) {

        for (Account eachAccount: trigger.New){
            eachAccount.Product_sales_price__c =  eachAccount.Product_sales_price__c - (Discount__c/100)*eachAccount.Product_sales_price__c;
        }            
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Suraj
Roopa S 1Roopa S 1
@Suraj Tripathi 47    
i tried that code its not calculating discount still its populating with actual price
mukesh guptamukesh gupta
Hi Roopa,

Please make sure your trigger is Activated. and also debug in trigger to get exact value

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh