Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

Invalid initializer type List found for Map

Asked by Caroline Brown Apr 16, 2021 1.8K views 1 answer
Share

About this question

 I am new into apex development. I am getting an this error in my map:

Invalid initializer type List found for Map expected a Map with the same key and value types, or a valid SObject List

Why do I get this invalid initializer c error? How can I fix it?

Here is the code:

Trigger LastOnsiteVisit_SA on Event(Before insert, before update) { Set eventIds = new Set(); Set AccountIDZ = new Set(); for (Event evt: Trigger.New) { eventIds.add(evt.Id); AccountIDZ.add(evt.AccountId); } Set Accountset = new Set([SELECT ID FROM Account where ID IN: AccountIDZ]); Map mp2 = new Map ([SELECT AccountId, EndDateTime FROM Event WHERE RecordTypeId = '01270000000YSks' AND AccountId IN :AccountIDZ AND Type = 'Onsite Meeting' ORDER BY EndDateTime DESC]); for (Account acct: Accountset) { if (mp2.containskey(acct.id)) { acct.Last_Onsite_Visit__c = mp2.get(acct.Id).Date(); } } }


Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.