I'm trying to pass the old & newmaps as arguments to a future method using JSON method. I see the below error when it tries to deserialize the data. reference-Passing SObjects to Future
|FATAL_ERROR| System.TypeException: Invalid conversion from runtime type
OpportunityLineItem
toMap<Id,OpportunityLineItem>
//Trigger
if(Trigger.isUpdate && Trigger.isAfter){
if(CheckOpportunityLineItemRecursive_AC.runAfterUpdateOnce()){
if(!System.isFuture() && !System.isBatch()){
String jsonOldMap = JSON.serialize(Trigger.oldMap);
String jsonNewMap = JSON.serialize(Trigger.newMap); OpportunityLineItemTriggerHandler_AC.OnAfterUpdateAsync(jsonOldMap, jsonNewMap);
}
}
//Future method
public static void OnAfterUpdateAsync(String strOldMap, String strNewMap){
Map<Id, OpportunityLineItem> oldMap = (Map<Id, OpportunityLineItem>)JSON.deserialize(strOldMap, System.Type.forName('OpportunityLineItem'));
Map<Id, OpportunityLineItem> newMap = (Map<Id, OpportunityLineItem>)JSON.deserialize(strNewMap, System.Type.forName('OpportunityLineItem')); //do something
Please help me find what Im missing here. Thanks.