I have a String extDB_Table__c.inputString__c that looks like this:
||| is meant to be a delimiter between whatever values are in the string (comes after every value, including the final one).
SPN are all keys in a
Map<String,String> transMap, where the values are translations to the equivalent spelling of the concept in a multi-select picklist, e.g.
ECON --> Economics MTHS --> Math and Statistics SPN --> Spanish THE --> Theology
Sometimes I'll have another string Opportunity.MSP__c with a pre-existing value like
I'd like to optimize two different operations:
- Building a semicolon-delimited string outputStringA full of the "translated" values like
Math and Statistics;Economics;Spanish(when I know there's no Opportunity related to the extDB_Table__c record I'm processing and I have to create it)
- Building a semicolon-delimited string outputStringB that takes Opportunity.MSP__c into account and produces something like
Dance;Economics;Astronomy;Math and Statistics;Spanish(order and redundancy of
Economicsnot important as long it's not important when doing DML to multi-select picklists)
What Apex algorithms / code patterns would people suggest for building outputStringA and for building outputStringB as efficiently as possible? (I can think of a lot of ways to do it inefficiently...)
This is inside a loop through extDB_Table__c records. The delimiter pattern for extDB_Table__c.inputString__c is always the same; there is a branch inside the loop to determine whether I need to compute outputStringA or outputStringB.