You need to sign in to do that
Don't have an account?
Katherine Rowe
Best way to map values in a trigger - case vs else if
I've got the following trigger working, to map the value of an industry to a different industry:
Now I have to do that for a long list of industries, see below. What is the best way to write this in the trigger? Can I use something like a "case" method? Or does it need to be a bunch of else if statements?
trigger MapDataCOMIndustry on Account (before insert, before update) { for(Account a1: Trigger.new){ if(a1.industry=='Government'){ a1.industry='Emergency Services'; } } }
Now I have to do that for a long list of industries, see below. What is the best way to write this in the trigger? Can I use something like a "case" method? Or does it need to be a bunch of else if statements?
trigger MapDataCOMIndustry on Account (before insert, before update) { for(Account a1: Trigger.new){ if(a1.industry=='Government'){ a1.industry='Emergency Services'; } else if(a1.industry=='Agriculture'){ a1.industry='Agriculture & Fisheries'; } else if(a1.industry=='Apparel'){ a1.industry='Other'; } else if(a1.industry=='Banking'){ a1.industry='Finance'; } } }
All Answers
CustomMappings__c: Name = Salesforce standard industry
HSI__c = HSI Industry
you can then get these vales directly using
If that helps, please mark it solved.
A followup question... when using a custom setting for mapping, what do I do when I need the left value to be more than 40 characters? Because the name field won't let me go above 40. When I use the getInstance() method in my trigger, does it have to reference the name field, or can I use some other custom field that I make bigger than 40 characters?
For example, the first one below has more than 40 characters and it won't let me load it into the name field.
(left value) -> (right value)
"abcdefghijklmnopqrstuvwxyzbcdefghijklmnopqrstuvwxyz" -> "apple"
"abcdef" -> "banana"
"abcdefghijklmn" -> "grape"