How to Calculate discount for opportunity?

How to Calculate discount for opportunity in Salesforce based on percentage field?

Table of Contents

Introduction to scenario

→ Apex Trigger 5

Prerequisite

  • Create a Custom field on Opportunity “Discount” and the data type of this field should be percent.
  • Create a Custom field on Opportunity “Discounted Price” with Currency Data Type

Requirement

Develop an Apex Trigger on Opportunity so that when any opportunity is created and if the Discount & Amount field is not blank then calculate the discount and store it in the Discount Price field.

To Calculate the discount use the below formula and store it in a variable
Decimal discount = ( Discount * Amount ) / 100

To Calculate the Discounted Price use the below calculation and store it in a variable
Decimal discountedAmount = Amount – discount;

Hand on


					
				

Dispatcher Class


					
				

Handler Class


					
				

Outcome




Resources

Vaibhav Kumar
Vaibhav Kumar
Articles: 6

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from Panther Schools

Subscribe now to keep reading and get access to the full archive.

Continue reading