0

The source field has a picklist of values on it. But critically, the values in this field may not all match valid picklist values. For example:

Field_A__c picklist: Hamburger picklist: Hotdog

I want a proposed Field_B__c field to have a value based on the values in Field_A__c. So if Field_A__c's value is 'Hamburger', then Field_B__c's value should be 'Beef'. That sounds pretty simple, right?

My issue is what happens when Field_A__c has a value of 'Pizza'. But 'Pizza' is not one of those picklist values I noted above. How do I update Field_B__c's value in this scenario?

More Info

  • The current number of unique Field_A values is 10. This is specifically the amount of picklist items available to choose.
  • The current number of unique Field_B values is 5.
  • Some values of Field_A are not in the picklist values because the Restrict picklist... option is unchecked on the field & new "non-picklist" values could still be added.

I think this chart should help visualize what I want?

Field_A In Picklist Field_B
Pizza TRUE Dinner
Hamburger TRUE Dinner
Eggs TRUE Breakfast
Salad TRUE Dinner
Tuna Sandwich TRUE Lunch
Ice Cream TRUE Dessert
Toast TRUE Breakfast
Steak TRUE Dinner
Potato Chips TRUE Lunch
Tacos TRUE Dinner
Cake FALSE Dessert
Bacon FALSE Breakfast
Water FALSE Other
3
  • Welcome to Salesforce Stack Exchange (SFSE). More information is needed in order to attempt to help you. Please edit your question to include the following: (1) What is current number of unique Field_A values? (2) Unique Field_B values? (3) Are some values of Field_A not in the picklist values because A) it is "old" data (e.g., from before the field became a picklist field, "retired" picklist values, bulk data load)? Or B) because the Restrict picklist... option is unchecked on the field & new "non-picklist" values could still be added? (Or create a "C)" if something else.)
    – Moonpie
    Commented Sep 9, 2021 at 0:53
  • Thanks - all that is helpful. It would be simpler if you wanted the 10 Field_A picklist values to match up to the 5 Field_B values, and then everything else NOT in the Field_A picklist get lumped into one value in Field_B. You have added layers of complexity to want the Field_A non-picklist values to then be parsed and matched with specific Field_B values....
    – Moonpie
    Commented Sep 9, 2021 at 1:15
  • 2
    BTW, "Bacon" should map to "Breakfast", "Lunch", Dinner", "Supper", "Dessert", "Snack", "Other"... Just sayin'
    – Moonpie
    Commented Sep 9, 2021 at 3:13

1 Answer 1

2

The simplest solution would be if you wanted all non-picklist values of Field_A to cause a value of "Other" in Field_B.

But since all of your non-picklist Field_A values do not map to the same Field_B value; and since in the future new Field_A values could be added that need to map to specific Field_B values; it seems that there is going to have be list maintenance done somewhere by someone.

Looking closely at your samples, it turns out that the values of Field_B do not really depend on whether the value of Field_A is in the picklist - the Field_B values just depend on the actual values of Field_A. That makes using a formula field more plausible.

It is a little bulky, but if you want admins to be able to maintain this whenever new Field_A values are added, then you could make Field_B a text formula field like this:

CASE(
  Field_A__c,
  "", "",
  "Hamburger", "Dinner",
  "Pizza", "Dinner",
  "Salad", "Dinner",
  "Steak", "Dinner",
  "Tacos", "Dinner",
  "Eggs", "Breakfast",
  "Toast", "Breakfast",
  "Bacon", "Breakfast",
  "Tuna Sandwich", "Lunch",
  "Potato Chips", "Lunch",
  "Ice Cream", "Dessert",
  "Cake", "Dessert",
  "Other"
)
  • The "", "", line makes Field_B blank when Field_A is blank. (This could probably be left out if Field_A is required.)
  • The "Other" as the last item makes any non-blank value in Field_A which is not explicitly listed here show an "Other" in Field_B. This might 'buy you time' when a new Field_A value gets added until the formula could be updated. (Or you could explicitly list which values you want to be "Other", and then let the last 'default' value be something like "Not yet determined" which could be a signal that the Field_A value needs to be added to this list.)

This could be done in Apex, but that would need developer maintenance whenever a new Field_A value is added - unless the code was made dynamic to read a mapping of Field_A > Field_B values from an admin-maintained source. But to me - as much as I love Apex - that seems a bit over the top for this.

Similar thought regarding a Flow - it seems like overkill in this case.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .