You need to sign in to do that
Don't have an account?
prasanth kumar 31
how to write discount apex class
HI I'm New to Developing Can you please let me Know how to write Applying Discount on Record using trigger and apex Class. please send me code i'm able to understand or below is my apex class code, please Modify it.
Public Class PenClassdemonstration {
Public Static Void applyDiscountPen (list<pen__c> varpenslistNew) {
for (pen__c varp : varpenslistNew) {
if(varp.penamount__C >= 100) {
varp.penamount__C = varp.penamount__C - 20;
}
}
}
}
Public Class PenClassdemonstration {
Public Static Void applyDiscountPen (list<pen__c> varpenslistNew) {
for (pen__c varp : varpenslistNew) {
if(varp.penamount__C >= 100) {
varp.penamount__C = varp.penamount__C - 20;
}
}
}
}
I would suggest you check the formula field as you can simply use a formula field that is of type number that automatically calculates this value, you can see these implementations in the below links:
>> https://salesforce.stackexchange.com/questions/47248/formula-to-calculate-discounts
>> https://developer.salesforce.com/docs/atlas.en-us.usefulFormulaFields.meta/usefulFormulaFields/useful_advanced_formulas_discounting.htm
If you want to use trigger you use the below snippet and modify as per the usecase:
Please do note that this is a sample snippet and you need to modify it accordingly.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
To help, we need to know the data model. What are the objects and fields to be used.