I am having two textfields consider A and B. When i enter a value for B, the corresponding value should be passed in Field A.


Field A is Dependant on Field B Values IF Field A IS EMPTY it can be saved IF Field B has any of the following values "1111" or "1112" then the field A should get autopopulated with a value "ABCD" .If other than the above said values are entered, Field A should be able accept values that should be in the length of 4 characters.

Can we Attain this by validation rule or do we need any other way to achieve it rather than using APEX/VF page. IF possible please provide me the guidance with possible ways or links.

2 Answers 2


This will require Apex and Visualforce. Validation rules in Salesforce are only capable of Boolean responses; the field's value is either valid or not. This could be used in your situation to determine if a user can change the value of field A, but not to populate it.

Fields can be automatically populated if they are formula fields, but formula fields are always read-only and thus do not meet all of your requirements.

Your best option is to create a Visualforce page with an extension controller. Encapsulate your logic into the extension controller and you will be able to provide a user-friendly interface to handle this, perhaps using JavaScript to dynamically enable or disable field A as necessary (Note: that is not a substitute for server-side validation.)

  • Thank you soo much Mike for your spontaneous answer. i will work on it and update the queries.
    – Mr.Blend
    Commented Aug 30, 2013 at 11:51

Do you need instant field upates while the user types? If not the combination of one or multiple validation rules and a workflow rule that triggers a workflow field update to fill the dependent fields on save should be sufficient for your case. I would strongly recommend to evaluate this option as every piece of code increases your maintenace efforts (sb coding -> testing -> deployment to prod) so I always recommend configuration over code (and I'm authorized APEX & VF instructor so I love coding :-)

  • 1
    I prefer clicks to code, too, but given the mix of circumstances I think that might be confusing for the users. If somebody thought they could change it, entered a value, and then a workflow changed it that could cause support problems. Though that could be countered through end-user training.
    – Mike Chale
    Commented Aug 30, 2013 at 13:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .