Activity › Forums › Salesforce® Discussions › Is it possible to Cast sObject dynamically?
Tagged: Map, Salesforce sObject, Schema
-
Is it possible to Cast sObject dynamically?
Posted by Piyush on April 29, 2016 at 9:05 AMIs it possible to Cast sObject dynamically in Salesforce .
shariq replied 7 years, 7 months ago 6 Members · 5 Replies -
5 Replies
-
- [adinserter block='9']
-
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); \\Schema.getGlobalDescribe() will give you all sObject type present in your org.
Schema.SobjectType oType = gd.get(‘account’);
account object_instance = (account)oType.newSObject(); -
Map gd = Schema.getGlobalDescribe();
Schema.SobjectType oType = gd.get(ObjectName)sobject object_instance = oType.newSObject();
-
Hi
Firstly we have to find out all sObject present in our Org -:
Map<String, Schema.SObjectType> mapofallSObject = Schema.getGlobalDescribe();
Schema.SobjectType objecttobeCast = mapofallSObject.get(‘Account’);
Account object_instance = (Account)oType.newSObject();
Thanks
-
Hi,
You can use standard schema class for taking out sobject detail(its properties) –
Map<String, Schema.SObjectType> sobjectMap= Schema.getGlobalDescribe();
Schema.SobjectType typeOfObject= sobjectMap.get(‘sobject__c’);
Sobject__c obj= (Sobject__c )typeOfObject.newSObject();
Hope this helps.
Log In to reply.