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
PlainviewPlainview 

Validation Rule for Dependent Picklist Field in Visualforce Page

We have a field on our Opps. layouts, "Reason," which is a dependent picklist field, with the controlling field being "Stage."

We would like the Reason field to be required when the Stage field is set to "Closed Won," "Closed Lost" or "Closed Funnel Purge."

Because of a Visualforce page ("opportunityCustomlayout"), the Reason field is not showing as required, even though it is listed as a dependent field under the Field Dependencies in the field definition settings.

Also, a Validation Rule did not work because of the customization made via the Visualforce page, which overrides the standard functionality; we cannot implement a Validation Rule against a Visualforce page.

I am resourcing for some help to write the code into the Visualforce page to make the Reason field required per the above criteria.

Thanks.
PratikPratik (Salesforce Developers) 
Hi,

You can refer to this post:
https://developer.salesforce.com/forums/ForumsMain?id=906F000000097eYIAQ

Hope this will help!

Thanks,
Pratik
PlainviewPlainview
Thanks, Pratik - this looks promising. Will have to try over weekend as to not to disrupt users - our sandbox and production environments do not match, unfortunately.

Question: Does it matter where in the VF page that I add this and/or the tag?

Thanks again very much,
Julien
PlainviewPlainview
Added this but still not working - anybody have any thoughts:

if (theOpp.StageName == 'Closed Won'){ 
            if (theOpp.Lost_Reason__c == null || theOpp.Lost_Reason__c == '')
      {theOpp.Lost_Reason__c.addError( 'You must select a reason');}
        }
        if (theOpp.StageName == 'Closed Lost'){ 
            if (theOpp.Lost_Reason__c == null || theOpp.Lost_Reason__c == '')
      {theOpp.Lost_Reason__c.addError( 'You must select a reason');}
        }
        if (theOpp.StageName == 'Closed Funnel Purge'){ 
            if (theOpp.Lost_Reason__c == null || theOpp.Lost_Reason__c == '')
      {theOpp.Lost_Reason__c.addError( 'You must select a reason');}
        }