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
santhosh konathala 8santhosh konathala 8 

How to avoid an user if he selected more than 3 values in a multi select pick list field an error message should be displayed using a trigger?

sslodhi87sslodhi87
Hi Santosh,

Here is demo code for same.
 
for(Customobject__c obj : Trigger.new)
{
        if(String.isNotEmpty(obj.customPicklistField__c)  && obj.customPicklistField__c.split(';').size() > 3)
        {
                  obj.addError('You can not select more than 3 values in pick-list');
        }
}

Please let me know if this works.

Thanks
santhosh konathala 8santhosh konathala 8
It's not clear to me