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
cldavecldave 

Validation to compare multiple fields for Duplicate Data

Hi,

I'm trying to create a validation to be able to compare about 35 email fields (from same record) to see if any have duplicate data.

Basically if example email1 and email 7 have same email address validation should prevent me from saving until it is fixed

I'm at a lost on where to start :(  If anyone could help, I would appreciate it

Thank you in advance
Best Answer chosen by cldave
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@cldave:

You could either write 35 validation rules with 34 lines of comparision in each,  or you could create a trigger with before update & before insert events, check the same logic and return an error accordingly! 

Either way the logic in both cases will have similar lines of code!, but in trigger, we can have a better logic written, where we can easily check the number of occurences of each email entered, if it is greater than 1 throw an error.

Hint: If it is in trigger, you can serialize the record you are dealing witha and verify the number of occurances of each email field.

I dont see any other option other than these two :).

Hope it helps.

thanks,
balaji

All Answers

Balaji Chowdary GarapatiBalaji Chowdary Garapati
@cldave:

You could either write 35 validation rules with 34 lines of comparision in each,  or you could create a trigger with before update & before insert events, check the same logic and return an error accordingly! 

Either way the logic in both cases will have similar lines of code!, but in trigger, we can have a better logic written, where we can easily check the number of occurences of each email entered, if it is greater than 1 throw an error.

Hint: If it is in trigger, you can serialize the record you are dealing witha and verify the number of occurances of each email field.

I dont see any other option other than these two :).

Hope it helps.

thanks,
balaji
This was selected as the best answer
cldavecldave
Ok that's what I thought, but wanted to find a way that did not invovle a trigger.

But tyvm for info, I appreciate it