Skip to content

Instantly share code, notes, and snippets.

@britishboyindc
Last active February 23, 2017 22:28
Show Gist options
  • Save britishboyindc/feea783c0c1b84b87878d8fc83511e5e to your computer and use it in GitHub Desktop.
Save britishboyindc/feea783c0c1b84b87878d8fc83511e5e to your computer and use it in GitHub Desktop.
//Assume Asset object has name, lookup to user and picklist called Category
//Store results in a map
Map <String, List<String> > assetmap = new Map <String, List<String> >();
//Loop through assets
for (Asset__c tempasset : [Select Name, Category__c FROM Asset__c WHERE User__c = '0053000000AD9YT'] ) {
List<String> tempassetlist;
//if map already contains category, add to existing list
If (assetmap.containskey(tempasset.Category__c) ){
tempassetlist = assetmap.get(tempasset.Category__c);
}
//or create empty list
else {
tempassetlist = new List<String> ();
}
//Update list
tempassetlist.add(tempasset.Name);
//update map
assetmap.put (tempasset.Category__c, tempassetlist);
}
//see results
system.debug(assetmap);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment