+ Start a Discussion
niki s 7niki s 7 

How to update opportunity field whenever there is change in stage

Suppose in opportunity I am changing the stage name from stage1 to stage2 then I need to set the checkbox as true.

How to achieve this using configuration
ShivankurShivankur (Salesforce Developers) 
Hi Niki,

You can create a formula field with return type as Checkbox. The formula will be:
​IF( AND( ISCHANGED([Opportunity].StageName), TEXT([Opportunity].StageName) = 'Stage 2', TEXT(PRIORVALUE([Opportunity].StageName)) = 'Stage 1' ) ,true,false)
This checkbox will be checked (true) when the Stage is changed from 'Stage 1' to 'Stage 2'. In all other cases it will remain unchecked (false). 

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.
Suraj Tripathi 47Suraj Tripathi 47

Hi niki,

You can write a trigger for this.

trigger OpportunityTrigger on Opportunity (before update) {
    if(trigger.isBefore && Trigger.isUpdate){		
		for(Opportunity op:Trigger.new){
		if(trigger.newMap.get(op.id)=='Stage 2' && trigger.oldMap.get(op.id)=='Stage 1'){
		op.checkBox=true;
		}
		}
    }
	}

Please mark it as the Best Answer so that other people would take references from it.

Thank You