I am trying to cast the type Map<String, SObject>
to Map<String, EmailTemplate>
, my code as follows:
EmailTemplate emailTemplate = [SELECT Id FROM EmailTemplate LIMIT 1].get(0);
SObject sobj = (SObject) emailTemplate;
Map<String, SObject> sobjectMap = new Map<String, SObject>();
sobjectMap.put('red', sobj);
Map<String, EmailTemplate> emailTemplateByColorMap = (Map<String, EmailTemplate>) sobjectMap;
I am getting the following error message:
Error on line 9, column 1: System.TypeException: Invalid conversion from runtime type Map to Map AnonymousBlock: line 9, column 1
Any idea why is throwing an error message? An SObject can be cast to EmailTemplate. Right?