+ Start a Discussion
Steve Berley [Left Propeller]Steve Berley [Left Propeller] 

writing generic code - how to abstract/dereference a variable to subject type

I'm writing some generic code and want to refer to an sobject type using a variable.  The goal being to write code similar to ...
string t = 'custom_object__c';
list<t> objs = new list<t>(); // creating a list of custom_object__c's
Of course, string is not the right type for t, but thi sis the idea I'm trying to accomplish

Can this even be done in apex?  


Alain CabonAlain Cabon
Hello Steve,

Apex considers the concept of "dynamic apex" for genericity.   

More generally: the new way of writing the classes and triggers in Salesforce is to use the concept of separation of concern (service layer principles, domain and selector layor and unit of work among other thing)