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
Roshan 10Roshan 10 

Illegal assignment from List<Account> to List<Id>

List<Id> accountIds = [Select Id from Account];

Run the above code in Execute Anonymous window and I am receiving the above error.
Can you please help me understand why this error is occuring or how I can overcome this error
Best Answer chosen by Roshan 10
Amit Chaudhary 8Amit Chaudhary 8
Hi Roshan,

Please update your code like below
List<Account> accountIds = [Select Id from Account];

IF you want id only
Map<Id,Account> mapAccount = new Map<Id,Account>([select id from account]);
Set<ID> SetACCID = new Set<ID>();
SetACCID = mapAccount.keySet();



Let us know if this will help you