Development questions

How do you directly populate a Map<Id, SObject> from a SOQL query without using a for loop? (new Map<Id, Account>([SELECT Id, Name FROM Account])).

Pass the query directly into the Map constructor. Salesforce uses each record's Id as the key.

apex
Map<Id, Account> accMap = new Map<Id, Account>([SELECT Id, Name FROM Account WHERE Industry = 'Tech']);
Account a = accMap.get(someId);

This avoids manual loops, is concise, and counts as one SOQL query. It works only for keys that are Ids; for other keys use a loop.

soqlapexcollections