function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bibbo84bibbo84 

Dynamic Cast of type of List

Hi,

 

i have to make an upsert of a list. But for me the type of list is kwown at runtime.

How i create a list or right type?-->is't not possible to make an upsert of a list of sObject.

 

List<SObject> listtoupsert=new List<SObject>();

String type='Lead';

//it's possible to make something like this?

List<type> listtoupsert2=new List<type>();

 

 

 

logontokartiklogontokartik

I am not sure if this meets your purpose, but using the SObjectType and getGlobalDescribe, you can basically build the object at run time. Just use the same generic object List and identify the type for all the other operations/

 

 String type = 'Lead'
SObjectType sType = Schema.getGlobalDescribe().get(type);
SObject tObject = sType.newSObject();