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
Ad_InfosysAd_Infosys 

Query in using Maps

I want to create a map
 

Map<ID, Contact> m = new Map<ID, Contact>([select id, lastname from contact])

 

The key value ID will be the record id for contact.

I want Account ID in the key set for every record of contact returned. How can I pick that.

 

 
micwamicwa
Code:
List<Contact> contactList = [Select c.AccountId, c.Id, c.Name from Contact c LIMIT 1000];
Map<Id,Contact> contactAccountIdMap = new Map<Id,Contact>();

for(Contact c : contactList){
   contactAccountIdMap.put(c.AccountId, c);
}