Import Object Data Directly into a Map


Paul's Salesforce Blog

Here’s a neat trick that I found.  You can use it to import object data directly into a Map, indexed by the Object’s ID.

Here is an example:

Map<ID,Contact> contactMap = new Map<ID,Contact>([select id, name, phone, email from contact]);

 

This will import the results of the SOQL query directly into the Map!

 

I hope you find this as useful as I do.

View original post