-1

Illegal Asiignment From List To Map

1

Please Help Me On This Error

vimuth
  • 5,064
  • 33
  • 79
  • 116
  • Welcome! Can you please provide a [mre]? See [ask] for further guidance. Can you please read about [the problems with images of text](//meta.stackoverflow.com/a/285557/11107541) and then [edit] to convert your images of text into actual text? Likely useful: [/help/formatting](/help/formatting) – starball Jan 11 '23 at 07:45
  • Please read about [how to ask a proper "Where's the bug / Fix my code" question](//meta.stackoverflow.com/a/253788/11107541) and apply what you learn to improve your question post. – starball Jan 11 '23 at 07:46
  • Can you please [edit] to pose a clear, precise question? Maybe your question can be inferred, but this whole site is based on a framework of Q&A, so for the health of the framework, please ask one. You can see [ask] for guidance. Note: ['Can somebody help me?' is not really a question by our community's standards](//meta.stackoverflow.com/a/284237/11107541) – starball Jan 11 '23 at 07:46

1 Answers1

0

You can't assign, the types are incompatible. You can use the map constructor that takes a list as argument

Map<Id, Account> myMap = new Map<Id, Account>([SELECT Id, Name FROM Account LIMIT 10]);

or if you have existing map - you can call putAll on it.

Map<Id, Account> myMap = new Map<Id, Account>();
// some other code, maybe even adding some items to map manually
// and eventually
myMap.putAll([SELECT Id, Name FROM Account LIMIT 10]);
eyescream
  • 18,088
  • 2
  • 34
  • 46