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
rajesh k 10rajesh k 10 

How to write a workflow rule when checkbox is checked update discount field in salesforce?

Hi,
           I have one checkbox field in my object when that checkbox is cchecked automatically update discount field to 30% How?

help me..
Abilash Kosigi 8Abilash Kosigi 8
Hi Rajesh,

Instead of Workflow, you can create a field with a formula.
Suppose if the checkbox field is Discount Required,  and the Discount Percentage is the field which shows your required percentage -- create Discount Percentage field with formula type and write the below formula  and save the field. 

IF ( Discount_Required__c  = true, 30 , 0 )



User-added image


Please mark this as Best Answer, if this answers you query :).
rajesh k 10rajesh k 10
Hi,
        Using trigger how to write?

please help me..........
Abilash Kosigi 8Abilash Kosigi 8
Trigger:

trigger calculateDiscount on Account (after update) {
if(CheckRecursiveTrigger.runOnce()) {
for (Account acc: Trigger.new)
{
Account a = [select Id,  Discount_Required__c, Discount_Percentage__c from Account where Id IN : trigger.new];
System.debug(a.Discount_Required__c);
if (a.Discount_Required__c == true)
{
a.Discount_Percentage__c = 30.00;
}
else
{
a.Discount_Percentage__c = 0.00;
}
update a;
}


}
}



Class:


CheckRecursiveTrigger Class:

public class CheckRecursiveTrigger {
    private static boolean run = true;
    public static boolean runOnce(){
        if (run)
        {
            run=false;
            return true;
        }
        else
        {
            return false;
        }
    }

}


Here is the code you requested. However, discount percentage field is editable in the pagelayout in this case. You should make it readable in profiles.

Please mark this as Best Answer, if this answers you query :).