Last active
          February 23, 2017 22:28 
        
      - 
      
 - 
        
Save britishboyindc/feea783c0c1b84b87878d8fc83511e5e to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | //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