The scenario is, I want to execute the validation rules based on the condition. For example:

I have added the required field validation rule for firstName, LastName, Phone, Address in the Contact object, and have one custom field 'ContactType' picklist which contains direct/indirect values. Now, if I select 'direct' in the picklist, only FirstName, LastName, Address fields are required and Phone is not required field to save the data. When select 'indirect', some fields like FirstName, LastName, Phone should be required fields But not Address field.

Can anyone suggest how to achieve this scenario by using coding using LWC? Thanks in advance.

  • So you want the component to dynamically reflect which values the user needs to fill out when ContactType changes? If that's the case, this is easy to do with a required attribute and a change handler.
    – nbrown
    May 29, 2020 at 19:36
  • Why not just let Validation Rules do that job?
    – Adrian Larson
    May 29, 2020 at 19:46
  • @AdrianLarson: How this will work? In the application, 'ContactType' picklist is from the different object and the validation rules are from contact Object. When i choose the picklist in one page, click on next, the contact form will appear. and based on picklist selection, this form should execute the validation rules.
    – RKCY
    May 29, 2020 at 19:54
  • @nbrown:- I should use only validation rules instead of required attributes.
    – RKCY
    May 29, 2020 at 19:55
  • @RKCY, you didn't mention that ContactType is on another object. That complicates things. Is there a relationship between Contact and this other object? EDIT: Also, is there a good reason for capturing ContactType on another object? It sounds like something better left on the Contact itself and can be represented with a Record Type.
    – nbrown
    May 29, 2020 at 20:08


You must log in to answer this question.