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
sudhir kokilasudhir kokila 

how to query all the accounts and build a map with account name as key and account as value

Hemant_SoniHemant_Soni
Hi,
Please try below one.
Map<String, Account> mapAccounts = new Map<String, Account>();

for(Account oAcc : [SELECT ID, Name FROM Account limit 10]){
     mapAccounts.put(oAcc.Name, oAcc);
}

Thanks
Hemant​​​​​​​
ASIF ALIASIF ALI
For All Accounts , Remove Limit 10
Map<String, Account> mapAccounts = new Map<String, Account>();

for(Account oAcc : [SELECT ID, Name FROM Account ])
{
     mapAccounts.put(oAcc.Name, oAcc);
}