0

I have a multi-select picklist with many items, however I want the total number of characters to be less than 60. For example a user can select this: apple car banana pineapple watermelon grapefruit melon, but not: apple car banana pineapple watermelon grapefruit melon strawberry because that would be more than 60 characters.

I'm getting an error (items__c is a multi-select picklist field. Multi-select picklist fields are only supported in certain functions), so how can I make my Validation Rule work?

LEN(items__c) >  60)

1 Answer 1

1

I don't think you would be able to count the characters of a multipicklist field in a validation rule or even validation + formula combination.


You might have to roll your own before trigger that counts the length of the string & adds an error if it exceeds any particular length. You can optionally eliminate the value separator (;).

trigger SObjectTrigger on SObject__c (before insert, before update) {
    for(SObject__c record: Trigger.new){
        if(record.items__c != null && record.items__c.replaceAll(';', '').length() > 60){
            record.addError('Items__c', 'Characters can\'t exceed 60');
        }
    }
}
1
  • 1
    Can confirm, all my digging has turned up empty for validation rules. Multiselect picklist has a limited number of supported formula functions, none of which will help OP with their problem (documentation: help.salesforce.com/s/…). Trigger is the way to go. Jan 27 at 12:18

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.