Friday 9 September 2016

Concatenate Checkbox Fields Label In Formula Field In Salesforce

      Hi folks. Feeling good to back and write something useful. So today am gonna write about formula field effects.
Scenario : I have checkbox fields for sunday, monday, tuesday, wednesday, thursday, friday and saturday. I want to show only days that are true with comma separated strings. Below picture depicts the checkboxes.
Salesforce Checkbox field
Checkboxes

I've checked Monday and Thursday checkboxes. So output should be Moday, Thursday. 

Go to fields -> Create new fields -> Formula Field. I'm gonna call it as "True Days"

So do the formula now to bind only true days,

True_Days__c =

IF(Sunday__c, 'Sunday' & IF( 
OR(Monday__c, Tuesday__c, Wednesday__c, Thursday__c, Friday__c, Saturday__c), ',', '' 
), '') & 
IF(Monday__c, 'Monday' & IF( 
OR(Tuesday__c, Wednesday__c, Thursday__c, Friday__c, Saturday__c), ',', '' 
), '') & 
IF(Tuesday__c, 'Tuesday' & IF( 
OR(Wednesday__c, Thursday__c, Friday__c, Saturday__c), ',', '' 
), '') & 
IF(Wednesday__c, 'Wednesday' & IF( 
OR(Thursday__c, Friday__c, Saturday__c), ',', '' 
), '') & 
IF(Thursday__c, 'Thursday' & IF( 
OR(Friday__c, Saturday__c), ',', '' 
), '') & 
IF(Friday__c, 'Friday' & IF(Saturday__c, ',', ''), '') & 
IF(Saturday__c, 'Saturday', '')




From above formula field, we are just binding only the true values. Now save the field and see the formula field in detail page. Magic happened. It is not appending comma's before and after the strings.

formula field
Formula Field


put your thoughts in comments. Thanks!.

2 comments: