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
Anirudh Sharma 5Anirudh Sharma 5 

Picklist restrictions

I have a multi pick list field and It has 7 values but the requirement is user can only select 2 values but not more than two. so can you tell me how to do this, i dont have any ideas. 
Carlos Campillo GallegoCarlos Campillo Gallego
Hi Anirudh,

I think you can try with a validation rule, but it's not very fancy at all... You can use INCLUDES(multiselect_picklist_field, text_literal)
Determines if any value selected in a multi-select picklist field equals a text literal you specify. Using this for every combination of two of your picklist values should work, but it'd be a bit ugly...

Regards
sharathchandra thukkanisharathchandra thukkani
use javascript/jquery to put this validation if it a visual force page
ManojjenaManojjena
HI Annirudh,
If your layout is standard then you need to write trigger which wil help .I don't think validation rule an djavascript will help in this case .If you have VF page then javascript will help .
Just added a sample trigger replace your object name and field name in the trigger and test .
trigger multiSelectPickListValueSelectionRestriction  on Account (before insert,before update ) {
  for (Account acc :Trigger.new ){
    if(acc.DemoMultiPickList__c.split(';').size() >2 ){
        acc.addError('YOu can only select two value');
    }
  }
}

Let me know if it helps !!
Thanks 
Manoj