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
Luke Bray 9Luke Bray 9 

Populate a field based on value of multiple fields

I have a custom field, Field A. This field should be populated with one of 3 values based on the combination of 3 other fields Field 1, Field 2 and Field 3. 

There are 44 different possible combinations of Fields 1, 2 and 3 so making Field A a formula field is not possible due to character limits. 

I have tried to make a concatenation formula field of fields 1, 2 and 3 however still can have 44 possible concatenations and do not know of a good way to use this field to populate Field A. 

Can anyone suggest what I might do here? 
Best Answer chosen by Luke Bray 9
Ashvin JAshvin J
Hi Luke, 

You will have to switch to customization here. 

Field A will be updated from backend Apex code using trigger. 

All 44 possible combination needs to be configured somewhere (Custom label with comma spearated values, custom setting or custom metadata type). 

psedo trigger will look something like this. 

Trigger on sobject (before insert, before update){
     list<String> possibleCombinations = system.label.possibleCombinations.Split(',');
     for(sobject obj : trigger.new ){
           String combinedFieldValues = obj.Field_1__c + obj.Field_2__c + obj.Field_3__c ;
           if(possibleCombinations.contains(combinedFieldValues )){
                   obj.Field_A__c = combinedFieldValues;
           }
     }

}

Best Regards,
Ashvin

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi Luke,

Greetings!

You can achieve this using process builder please refer the below blog for the sample process builder with the screenshots:

https://www.forcetalks.com/salesforce-topic/how-to-concatenate-two-and-more-field-values-in-formula-of-salesforce-process-builder/

Please mark it as best answer if it helps you to fix the issue.

Thank you!

Regards,
Shirisha Pathuri

 
Luke Bray 9Luke Bray 9
Hi Shirisha, I don't think your solution answers my question. I am not struggling to do the concatenation. My struggle is to populate a field based on 44 different combinations of values. 

I suppose I could have a process builder with 44 nodes but that will be cumbersome and not very practical to maintain. 
Ashvin JAshvin J
Hi Luke, 

You will have to switch to customization here. 

Field A will be updated from backend Apex code using trigger. 

All 44 possible combination needs to be configured somewhere (Custom label with comma spearated values, custom setting or custom metadata type). 

psedo trigger will look something like this. 

Trigger on sobject (before insert, before update){
     list<String> possibleCombinations = system.label.possibleCombinations.Split(',');
     for(sobject obj : trigger.new ){
           String combinedFieldValues = obj.Field_1__c + obj.Field_2__c + obj.Field_3__c ;
           if(possibleCombinations.contains(combinedFieldValues )){
                   obj.Field_A__c = combinedFieldValues;
           }
     }

}

Best Regards,
Ashvin
This was selected as the best answer
Luke Bray 9Luke Bray 9
Thanks Ashvin, I was worried I would have to do something like this as it will be hard to maintain the custom metadata. Thanks for your help.