+ Start a Discussion
Ravikant kediaRavikant kedia 

I have a problem in formula field.

I have  10 checkbox fields with  labels Checkbox1, Checkbox2, Checkbox3, Checkbox4, ------ So on .
And I have a formula field that return selected checkbox label with comma(,) separated values like Checkbox1, Checkbox2, Checkbox3, and so on.
Example : I select 4 chekbox , Checkbox 1, Checkbox 3, Checkbox 9, Checkbox 5 and formula will return Checkbox 1,Checkbox 3, Checkbox 5, Checkbox 9.
So how i can implement this functionality in minimum step as possible  .So please help me to resolve this issuse as soon as possible.
Thanks in Advance.
Jigar.LakhaniJigar.Lakhani
Hello Ravikant,

It looks like that is not possible using formula field. you must need to use apex trigger for it.
Below is apex trigger with trigger handler class which you can use for your scenario.

Here some assumption
Trigger is for account object = you can use your object
Result_Field__c = Text or TextArea field where you want to display the result like comma separated string

Apex Trigger
trigger AccountTrigger on Account (BEFORE INSERT, BEFORE UPDATE) {

	// Before Insert
	if (Trigger.isBefore && Trigger.isInsert) {
		AccountTriggerHandler.manageCheckBoxesLabels(Trigger.New);
	}
	
	// Befoer Update
	if (Trigger.isBefore && Trigger.isUpdate) {
		List<Account> listAccounts = new List<Account>();
		for (Account objAccount:Trigger.New) {
			if (objAccount.Checkbox1__c != Trigger.OldMap.Get(objAccount.Id).Checkbox1__c 
				|| objAccount.Checkbox2__c != Trigger.OldMap.Get(objAccount.Id).Checkbox2__c 
				|| objAccount.Checkbox3__c != Trigger.OldMap.Get(objAccount.Id).Checkbox3__c ....same as upto 10 condition) {
				
				listAccounts.Add(objAccount);
			}
		}
		AccountTriggerHandler.manageCheckBoxesLabels(listAccounts);
	}
}

Apex Class
public with sharing class AccountTriggerHandler {

	public static void manageCheckBoxesLabels(List<Account> listAccounts){
		
		if (listAccounts != null && listAccounts.size() > 0) {
			for (Account objAccount:listAccounts) {
				
				objAccount.Result_Field__c = '';
				
				if (Checkbox1__c) {
					objAccount.Result_Field__c += Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().get('Checkbox1__c').getDescribe().getLabel() + ', ';
				}
				if (Checkbox2__c) {
					objAccount.Result_Field__c += Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().get('Checkbox2__c').getDescribe().getLabel() + ', ';
				}
				.........for 10 checkbox...
				if (Checkbox10__c) {
					objAccount.Result_Field__c += Schema.getGlobalDescribe().get('Account').getDescribe().fields.getMap().get('Checkbox10__c').getDescribe().getLabel() + ', ';
				}
				
				if (objAccount.Result_Field__c != null && objAccount.Result_Field__c.length() > 2) {
					objAccount.Result_Field__c = objAccount.Result_Field__c.substring(0, objAccount.Result_Field__c.length() - 2);
				}	
			}
		}
		
	}
	
}

Thanks and Cheers,
Jigar

 
John PipkinJohn Pipkin
This can be done with a formula field:
if(or(
checkbox1__c,
checkbox2__c,
checkbox3__c,
checkbox4__c,
checkbox5__c,
checkbox6__c,
checkbox7__c,
checkbox8__c,
checkbox9__c,
checkbox10__c),
left(
if(checkbox1__c, "Checkbox 1, ","") +
if(checkbox2__c, "Checkbox 2, ","") +
if(checkbox3__c, "Checkbox 3, ","") +
if(checkbox4__c, "Checkbox 4, ","") +
if(checkbox5__c, "Checkbox 5, ","") +
if(checkbox6__c, "Checkbox 6, ","") +
if(checkbox7__c, "Checkbox 7, ","") +
if(checkbox8__c, "Checkbox 8, ","") +
if(checkbox9__c, "Checkbox 9, ","") +
if(checkbox10__c, "Checkbox 10, ",""),
len(
if(checkbox1__c, "Checkbox 1, ","") +
if(checkbox2__c, "Checkbox 2, ","") +
if(checkbox3__c, "Checkbox 3, ","") +
if(checkbox4__c, "Checkbox 4, ","") +
if(checkbox5__c, "Checkbox 5, ","") +
if(checkbox6__c, "Checkbox 6, ","") +
if(checkbox7__c, "Checkbox 7, ","") +
if(checkbox8__c, "Checkbox 8, ","") +
if(checkbox9__c, "Checkbox 9, ","") +
if(checkbox10__c, "Checkbox 10",""))-2),'')