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
H 007H 007 

Hi, I Need a apex or JS code for If the opp. Status can not be set to closed without being set to price first in the picklist.

CharuDuttCharuDutt
Hii Harsh
Try Below Trigger
trigger OpportunityTrigger on Opportunity (before insert,Before Update) {
    
    if(trigger.IsBefore After && trigger.IsInsert){
        for(Opportunity oOpp  :Trigger.New){
        if(oOpp.StageName == 'Closed Won' && Price__c == null){
            oOpp.AddError('OppoTUnity Cannot Be Closed if Proce Is Not Set'); 
        }
      }
    }else if(trigger.IsBefore&& trigger.IsUpdate){
        for(Opportunity oOpp  :Trigger.New){
        if(oOpp.StageName == 'Closed Won' && Price__c == null && oOpp.StageName!= trigger.OldMap.get(oOpp.Id).StageName){
			oOpp.AddError('OppoTUnity Cannot Be Closed if Proce Is Not Set');            
        }
      }
    }
}
Please Mark It As Best Asnwer If It Helps
Thank You!