0

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 List

Invalid loop variable type expected Case was Id

Method does not exist or incorrect signature: void values() from the type List

1
  • pro tip: these kind of issues can be avoided by naming your lists/sets as plurals and your maps like casesById (i.e. thingsByKey)
    – cropredy
    Aug 11 at 18:37
1

You clearly expected caseUpdate to be a Map<Id, Case>. Remove your line where you declare it and update the line where you assign it to:

Map<Id, Case> caseUpdate = new Map<Id, Case>([/*query*/]);
for (Id caseId : caseUpdate.keySet())

Alternatively (and preferably as it is simpler), just stick with List<Case> and remove any references which expect it to be a Map.

for (Case record : caseUpdate)
{
    record.Last_Email_Status__c = record.EmailMessages[0].Status;
}
update caseUpdate;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.