I need to make mandatory Incorporation State/Province based on Incorporation Country. If Incorporation Country is Unites States or Canada The Incorporation State should be mandatory.

  • i need to add validation error for this if when become mandatory if that field is saved empty then one error should come – user24737 Aug 16 '16 at 10:06

You can use {Required="True"} attribute inside <apex:inputField>

| improve this answer | |
  • But then it would always be required. The question asks for how to only make the field required when the country is the United States or Canada. – martin Aug 16 '16 at 6:52
  • Try to use "apex:actionSupport" on change of picklist values which will call a method and try to send Boolean value "isBoolean" dynamically, i.e. Required= {!isBoolean}. I think this can be your solution. – kumar gaurav Aug 16 '16 at 7:19
  • I didn't get you Kumar. Where can i use action support tag how to send boolean to that and how to pass in class also, Can you please make me understand please, I'm just learning writing visualforce pages – user24737 Aug 16 '16 at 10:35

Try using a Validation Rule. You need it to return true when there should be an error, so its syntax should just check for either value, paired with a blank state.

        Incorporation_Country_Text__c = "Unites States",
        Incorporation_Country_Text__c = "Canada"
| improve this answer | |
  • Hi the field is Not pick list field is text fields both are – user24737 Aug 16 '16 at 10:55
  • That's not what your screenshot shows. Will update. – Adrian Larson Aug 16 '16 at 11:38
  • Sorry about that. Can you please give me suggestion on that – user24737 Aug 16 '16 at 12:32
  • @chris I've updated my code with recommendation. Also if you do make the field required on the page instead, you can do so conditionally. That is: required="{!OR(acct.Incorporation_Country_Text__c = "United States", acct.Incorporation_Country_Text__c = "Canada")}. – Adrian Larson Aug 16 '16 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy