I have the following method:
public static void updateCaseLastEmailStatus(List<EmailMessage> emUpdateCase) {
Id caserecordType = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('CaseRecordPage').getRecordTypeId();
List<Case> caseUpdate = new List<Case>();
List<Id> listIds = new List<Id>();
for (EmailMessage eMsg : emUpdateCase) {
listIds.add(eMsg.RelatedToId);
}
caseUpdate = new List<Case>([SELECT Last_Email_Status__c,
(SELECT Status FROM EmailMessages
ORDER BY CreatedDate DESC LIMIT 1 )
From Case WHERE RecordTypeId = :caserecordType AND ID IN: listIds]);
for(Id caseId : caseUpdate) {
Case myCase = caseUpdate.get(caseId);
myCase.Last_Email_Status__c = EMAIL_STATUSES.get(myCase.EmailMessages[0].Status);
}
update caseUpdate.values();
}
When I try to save the file, it gives me the following three error:
Method does not exist or incorrect signature: void get(Id) from the
type ListInvalid loop variable type expected Case was Id
Method does not exist or incorrect signature: void values() from the
type List
Best Answer
You clearly expected
caseUpdate
to be aMap<Id, Case>
. Remove your line where you declare it and update the line where you assign it to:Alternatively (and preferably as it is simpler), just stick with
List<Case>
and remove any references which expect it to be aMap
.