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
Erick MahleErick Mahle 

Validation Rules on Field Sets

Good Morning everyone,

Question: Can we run validation rules on entire field sets and trigger an error if one field is blank? Something to the tune of ISBLANK("FieldSetA")

The goal is to make certain fields required at each Opportunity Stage. I could write a very long validation rule that considers field by field, but every time we add a new field or remove one we'd have to re-work the validation rule. 

It would be nice to have something where we could have a Field Set for each Opportunity Stage, and run a VR that requires all to be filled out before moving on to the next stage.

Thoughts?
Tejpal KumawatTejpal Kumawat
Hello Erick,

You can't write Validation Rules on Field Sets, but can Write Trigger and Validate in before insert.

If this answers your question mark Best Answer it as solution and then hit Like!
Erick MahleErick Mahle
Thank you Tejpal! And would the trigger be written on top of the field set? Kind regards, Erick
Tejpal KumawatTejpal Kumawat
Yes Erick, Trigger will be on Opportunity before insert and use in code for example :
 
public List<Schema.FieldSetMember> getFields() {
        return SObjectType.[your_object_name].FieldSets.[your_fieldset_name].getFields();
    }

If this answers your question mark Best Answer it as solution and then hit Like!
Erick MahleErick Mahle
That's great! Thank you for the quick responses!