You need to sign in to do that
Don't have an account?
Mike Leach
Create Generic sObjects in Apex?
Is there a way to create generic sObjects in Apex? I'm looking for an equivalent to this:
string lateBoundType = 'MyCustomObject__c';
sObject obj = new sObject();
obj.Type = lateBoundType;
XmlDoc fields = //Create fields XML here
obj.Any = fields;
obj.Create();
Thanks!
-Mike
Not according to the Apex Code Developer's Guide - page 30 states:
The new operator still requires a concrete sObject type, so all instances are specific sObjects.
Hey
Does this help?
string lateBoundType = 'MyCustomObject__c';
sObject obj = Schema.getGlobalDescribe().get(lateBoundType).newSObject();
XmlDoc fields = //Create fields XML here
obj.Any = fields;
obj.Create();
I'll give this a try. Thanks!
-Mike