function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdcjoeysfdcjoey 

how to fecth data in map collection ?

how to fecth data in map collection ?
Best Answer chosen by sfdcjoey
sfdcMonkey.comsfdcMonkey.com
hi sfdcJoye
you can do it by get(key) method
here is example
 
Map<String, String> colorCodes = new Map<String, String>();
 colorCodes.put('Red', 'FF0000');
 colorCodes.put('Blue', '0000A0'); 
 String code = colorCodes.get('Blue');
 System.assertEquals('0000A0', code); // The following is not a color in the map String
i hop it helps you
thanks
mark it best answer if it helps you
 

All Answers

Mitesh SuraMitesh Sura
can you be more specific? 
sfdcMonkey.comsfdcMonkey.com
hi sfdcJoye
you can do it by get(key) method
here is example
 
Map<String, String> colorCodes = new Map<String, String>();
 colorCodes.put('Red', 'FF0000');
 colorCodes.put('Blue', '0000A0'); 
 String code = colorCodes.get('Blue');
 System.assertEquals('0000A0', code); // The following is not a color in the map String
i hop it helps you
thanks
mark it best answer if it helps you
 
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
If you want to learn about collection in salesforce please check below post
1) http://amitsalesforce.blogspot.com/2016/09/collection-in-salesforce-example-using.html

User-added image

Trigger using the Map:
 
trigger ContactTriggerWithMap on Contact (before insert) 
{
    Set<Id> SetAccountId = new Set<Id>();
    for(Contact cont: Trigger.new) 
 {
        if(cont.AccountId != null) 
  {
            SetAccountId.add(cont.AccountId);
        }
    }
    
    if(SetAccountId.size() > 0 ) 
 {
        Map<Id, Account> mapAccount = new Map<Id, Account>([Select Id, Name, Type from Account where Id IN :SetAccountId ]);
        for(Contact cont: Trigger.new) 
  {
            if(cont.AccountId != null && mapAccount.containsKey(cont.AccountId) ) 
   {
                cont.Type__c = mapAccount.get(cont.AccountId).Type;
            }
        }
    }
}
Let us know if this will help you