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.
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?)
Additional Validation rule in Opportunity:
Prevent user to changing a picklist value in Opportunity.
AND( ISPICKVAL( PRIORVALUE (StageName), "Stage 1"), ISPICKVAL(StageName, "Stage 3"), NOT ($Profile.Name = "System Administrator") )
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: