0

I have a multiselect picklist with ten values. One of these values cannot be chosen more than once on a record..

For example, multi_sel_picklist__c = "Aa" can only occur once on a record, with no duplicates of this value.

I tried this but it doesn't work:

(INCLUDES(multi_sel_picklist__c)"Aa", 0,1) > 1

Is it possible to validate that a selection is chosen only once? If so, how?

multi_sel_picklist__c is a on a custom object (Custom_Obj__C) and is linked to Account. You cannot have multi_sel_picklist = 'Aa' on the same account.

  • 1
    I think you're going to need Apex for this validation. – Adrian Larson Jan 30 '19 at 15:14
1

This fixed it... It checks that if the choice exists already on account, you can't add it again on Custom_Object__c.

AND (

(INCLUDES(multi_sel_picklist__c = "Aa")), (Account__r.Aa_field_on_account__c <> "") )

0

In such a case, validation rule might not suit for your requirement. You need to write a trigger with before insert and before update. And your trigger logic should be something like this

  • Trigger will be on child object with before insert and before update event.
  • Get all other child records of same account and create a map of it with key as Account Id and value as Set<String> of all child picklist values. (Split the multi-select picklist values and add that to the set)
  • Iterate over records which are in context, and check if that record has any value that is already present in the set. You will have to get the values using the Account Id field from map. (As you are having a multi-select picklist, you will need an additional for loop where you will split all the multi-select values by ';' and then loop over those values and check in the Set<string> returned from map using contains method)
  • If you find any duplicates, add error to that record.

Hope this helps !!

Note : If you will be uploading multiple records at a time, then you will have to accomodate those changes as well in the trigger i.e. you will have to check the values in the records which are in context as well.

  • It says incorrect parameters, expected 2 received 4. Are you sure the syntax is right? – Mia Genovese Jan 30 '19 at 16:12
  • Updated the answer, missed part of the formula. Check if this works – Vijay Ganji Jan 30 '19 at 16:20
  • Unfortunately this doesn't allow me to add even one 'Aa'... any idea of why that might be? – Mia Genovese Jan 30 '19 at 16:22
  • Updated the answer as validation rule won't suffice for your requirement. – Vijay Ganji Jan 30 '19 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.