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

Written by 

2x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *

*