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(); } } }