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
Ajay Kumar 583Ajay Kumar 583 

Need Solution for Opportunity task

Hi,
I dont want to  allow making Opportunity Stage = “Closed Won” or “Closed Lost” when the Opportunity Amount is greater or equal $500,000.

Thanks,

AJ

Best Answer chosen by Ajay Kumar 583
Deepali KulshresthaDeepali Kulshrestha
Hi Ajay,

You can do this with the help of the validation rule. Below is the formula for the validation rule for the same:

AND(OR(ISPICKVAL(StageName , 'Close Won') , ISPICKVAL(StageName , 'Close Lost')) ,  Amount >= 500000)

Also, please check the API of the fields before implementing any changes.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha 

All Answers

Ajay K DubediAjay K Dubedi
Hi Ajay,

Use bellow trigger it may helpful for you:
Trigger :
trigger TriggerOnOportunity on Opportunity (before update) {
    if(trigger.isBefore && trigger.isUpdate)
        {
            TriggerController.updateOppMethod(trigger.new);

        }

}

Apex Controller
public class TriggerController {
    public static void updateOppMethod(List<Opportunity> oppList){
        if(oppList.get(0).StageName=='Closed Lost')
        {
            List<Opportunity> NewOppList=new List<Opportunity>();
            
            NewOppList=[select Id,name,StageName,Amount from Opportunity where Id in: oppList];
            if(ollList.size()<=0)
            {
                for(Opportunity oppInst:NewOppList)
                {
                    if(oppInst.Amount >= 500000){
                        if(oppInst.StageName == 'Closed Won' || oppInst.StageName == 'Closed Lost'){
                            oppInst.addError('Ammount is greater then 500000 so you can not set stage name closed won or closed lost');
                        }
                    }
                    
                }
            }
        }
    }
    
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Deepali KulshresthaDeepali Kulshrestha
Hi Ajay,

You can do this with the help of the validation rule. Below is the formula for the validation rule for the same:

AND(OR(ISPICKVAL(StageName , 'Close Won') , ISPICKVAL(StageName , 'Close Lost')) ,  Amount >= 500000)

Also, please check the API of the fields before implementing any changes.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha 
This was selected as the best answer