+ Start a Discussion
Michael French 61Michael French 61 

Reference validation rule in apex/lightning

We have an SObject MyObject__c with a custom validation rule that says either FieldA__c or FieldB__c must be filled in, otherwise throw an error.

We want this to be reflected on custom lightning forms that we create for inserting or updating MyObject__cs. For example, if we have a form for inserting a MyObject__c, we want to be able to disable the save button until either FieldA__c or FieldB__c is filled in. We plan to add more fields with similar validation rules, so we would like to be able to do this dynamically.

Is there a way we can reference the validation rule either in Lightning or in Apex to dynamically mark that certain fields must be filled in when others arent? Or is the best way to just hard-code it in whatever lightning component we create?
Pablo Gonzalez Alvarez 3Pablo Gonzalez Alvarez 3
The validation rule will only work once the data has been passed to the server, in apex. So no, there's no way for this server-side validation to run in the client-side lightning component. You'll have to create the same logic in the javascript controller of the component