0

In Product I have a multiselect picklist called Zonelist. I just need to have the Zonelist value in a Map collection.

For example:

Product Name - HP Monitor
Zonelist - Zone1; Zone2; Zone3;

How can i include the Zone1,Zone2 and Zone3 as Key value in MAP collection for a single Product2 record?

  • 2
    What have you tried so far? Where are you stuck? Do you want the key to be order dependent? – Adrian Larson Apr 27 '17 at 15:45
  • It do not want to be order dependent. I was stuck in Mapping the query multi select picklist value of a record. @AdrianLarson – DOMINIC EDWARD Apr 27 '17 at 15:52
0

Assign the Picklist value to String array and loop it to assign the multipicklist value to Map as Key value.

Product2 p = [Select id, name,ZonePriceBookList__c, Family from
Product2 where Name =: 'HP Monitor'];
String[] PBAssign = p.ZonePriceBookList__c.split(';'); 
Map<String, String> PBMap = new Map<String, String> ();
for(String s : PBAssign){
   PBMap.put(s,s);
}
  • 1
    This has a high chance of collision. – Eric Apr 29 '17 at 16:18
  • Kindly suggest me a better solution @Eric – DOMINIC EDWARD Apr 29 '17 at 16:34
  • No. There is not enough information in your question to understand. I guess you may need to end up with a structure of Map<String,Product2[]> instead of a single value. How you plan to use it is important as well. If you are only working with ONE product2 record then your solution will be fine but then why do it at all.... – Eric Apr 29 '17 at 16:37
  • @Eric I am using only one Prouduct2 record. Based on the selected multiselect picklsit value of a Product2 record some calculation will be done in background. – DOMINIC EDWARD Apr 29 '17 at 16:45
  • very specifically it will do what you want. not bulkified, could either just check if the field contains a value or use the List of strings and not need a map but that all depends on the downstream code. – Eric Apr 29 '17 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.