Activity Forums Salesforce® Discussions Is it possible to Cast sObject dynamically?

  • Is it possible to Cast sObject dynamically?

  • Piyush

    Member
    April 29, 2016 at 9:05 am

    Is it possible to Cast sObject dynamically in Salesforce .

  • Nitesh Mishra ☁

    Member
    April 29, 2016 at 9:08 am
  • Gourav

    Member
    April 29, 2016 at 9:45 am

    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();

  • shalini

    Member
    April 29, 2016 at 10:24 am

    Map gd = Schema.getGlobalDescribe();
    Schema.SobjectType oType = gd.get(ObjectName)

    sobject object_instance = oType.newSObject();

  • Parul

    Member
    September 18, 2018 at 7:22 am

    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

  • shariq

    Member
    September 21, 2018 at 12:39 am

    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.

Viewing 1 - 6 of 6 posts

Log In to reply.

Popular Salesforce Blogs