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
tgk1tgk1 

Formula for multi-select picklist

Hi everyone.  I have a multi-select picklist that contains roughly 50 values.  I need to create a simple formula field that counts the number of values that were marked off in the mult-select picklist.

 

For instance, if two values were selected in the mult-select picklist, the value of the formula field would equal 2. 

 

I know this seems simple but I'm having trouble due to the field type.  Any help would be greatly appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

As multiselect-picklist only supported in some limited functions so it will be prety difficult to create a formula, not saying it is imposible. bUt better solution is to just calculate it a trigger.

 

try this

trigger CalculateCountMultiSelect on MyObject__c ( before insert , before update)
{
for(MyObject__c obj : trigger.new)
{
    List<String> l = new List<String>();
    if(obj.MultiPickList__c != null)
   {
      l = obj.MultiPickList__c.split(';')
    }
   obj.count__c =    l.size();
}
}

 replace you object and field name for multi-select picklist

Count__c is you Number field.

All Answers

Shashikant SharmaShashikant Sharma

As multiselect-picklist only supported in some limited functions so it will be prety difficult to create a formula, not saying it is imposible. bUt better solution is to just calculate it a trigger.

 

try this

trigger CalculateCountMultiSelect on MyObject__c ( before insert , before update)
{
for(MyObject__c obj : trigger.new)
{
    List<String> l = new List<String>();
    if(obj.MultiPickList__c != null)
   {
      l = obj.MultiPickList__c.split(';')
    }
   obj.count__c =    l.size();
}
}

 replace you object and field name for multi-select picklist

Count__c is you Number field.

This was selected as the best answer
Ankit AroraAnkit Arora

Here is the blog post which says similar thing you want. But its good to do with 4-5 values, as you have 50 then I also suggest you to go with apex.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

tgk1tgk1

Excellent- the trigger worked great.  Thanks everyone.

multi picklist validation rulemulti picklist validation rule

Great job Mr.sharma

Shashikant SharmaShashikant Sharma

Thnaks Mate,

 

Even though i am not in touch with developer community these Days, but happy to know my earlier work still has some wires connected.