Skip to main content
Hi SalesforceWizards

 

So below lines would explain better what I am trying to achieve:

 

public static void MethodName(System.Type typeName, String objInstance, String ListValues){

 

typeName obj = (typeName)JSON.deserialize(objInstance , typeName.class);

 

List<typeName> lst = (List<typeName>)JSON.Deserialize(ListValues,LList<typeName>.class);

 

// corresponding task if lst and obj are created successfully

 

}

 

But both the above lines which create List and Instance are throwing compile time error :"Invalid type typeName"

 

So the question here is :

 

Is there any workaround to this issue so that I can achieve what I am trying to do.

 

Is it even possible to create any class instance or List<thatClass> without specifying the hardcoded className i.e. just by using System.Type typeName of that class?

 

Any help would be much appreciated if it's possible.

 

Thanks
5 respuestas
  1. 8 may 2020, 15:06
    Hi Amnon

     

    typeName is just the receiving variable name so that would not make any issues I think.

     

    And Initially, I thought of using List<Object> only but was not able to access the object content like object.name as it was also throwing compile-time error.

     

    So is there any way we can access the content of object it if we use List<Object>?