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
Soundhariyaa MSoundhariyaa M 

trigger to update "Stage" field in Opportunity

I am completely new to Triggers.
My scenario is:
If "Call Completed" checkbox in Opportunity field is checked then "Stage" field in Opportunity Object must change to "Quotation".

Could anyone tell me how to acheive this?
I'm completely blank..
I would be glad if you suggest me how to master Triggers in Salesforce too.


Thanks in Advance !
 
sachinarorasfsachinarorasf
Hi Soundhariyaa,

Please use the below piece of code :
trigger OpprotunityTrigger on Opportunity (After insert, after update) {
   OpprotunityTriggerHandler.updateOppStage(trigger.new);
}

/********* trigger handler ************/
public with sharing class OpprotunityTriggerHandler {
    
    public static void updateOppStage(List<Opportunity> OpportunityList){
	if(OpportunityList.size() > 0){
	for(Opportunity oppObj :OpportunityList){
	if(oppObj.CallCompleted__c == true && oppObj.Stage != 'Quotation'){
	oppObj.Stage = 'Quotation';
	}
 }
	update OpportunityList;
 }
}
}

Also, do trailheads and more and more questions of triggers to master triggers. Here are the links of trailheads:
https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers

Please mark it as best answer if you find it helpful.

Kind regards,
Sachin Arora