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
Jimmy BrownJimmy Brown 

Illigle assignment from list to map?

Hi,
I want query some account and assign it into map but it show the Illigle assignment from list to map?
here is code > Map<id,account> accountMap=[select id,name from Account limit 10000];
Naresh AltokkNaresh Altokk
List<Account> accounts = [SELECT ID,NAME FROM ACCOUNT LIMIT10000];
Map<Id, Account> accountMap = new Map<Id, Account>( accounts );
List<Id> returnIds = new List<Id>(accountMap.keySet());
Suraj Tripathi 47Suraj Tripathi 47
Hi Jimmy Brown,
Please follow the below code:-
Map<id,account> accountMap=new Map<id,account>([select id,name from Account limit 10000]);

In the map if you want to assign a list you can't directly assign it, you have a pass that lists as a parameter of the constructor.

If you face any problem then post it.
Please mark it as the best answer if it helps you to fix the issue.

Thank you!

Regards,
Suraj Tripathi.