Opportunity field mandatory when an Salesforce Opportunity stage is changed

There are two ways possible to achieve the mandatory requirement for salesforce, one is standard salesforce validation rule and other is custom logic using apex trigger, its depends on the business logics,

for here, we can simply achive for the out of box solution for the salesforce validation rule.

For Example:

AND ( 
OR ( 
ISPICKVAL(StageName, "Closed - Lost to Competitor"), 
ISPICKVAL(StageName, "Closed - No Decision"), 
ISPICKVAL(StageName, "Closed - Project Canceled") 
), 
ISBLANK(Why_we_lost__c) 
)

Use case from Salesforce Community: (Validation Rule not triggering? If we lost, why?)

Also, refer the below youtube video to create a validation rule in opportunity object:

Additional Validation rule in Opportunity:

Example 1:

Prevent user to changing a picklist value in Opportunity.

AND(
ISPICKVAL( PRIORVALUE (StageName), "Stage 1"),
ISPICKVAL(StageName, "Stage 3"),
NOT ($Profile.Name = "System Administrator")
)

Example 2:

Making a field required when an Opportunity stage is changed to closed won or lost

AND(
OR(
ISNEW(),
ISCHANGED(StageName),
ISCHANGED(Competitor__c)
),
CASE(StageName, 
"Closed Won",1, 
"Closed Lost",1, 
0) = 1,
ISBLANK(Competitor__c)
)

Source from Salesforce:
https://help.salesforce.com/articleView?id=fields_about_field_validation.htm&type=0

(70)

Written by 

I am Sakthivel Madesh, a certified Salesforce Developer & Administrator working on Salesforce Technology since 2011. I am currently working in IBM Austraila as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 10 Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply