Activity Forums Salesforce® Discussions What is sObject casting?

  • Gourav

    Member
    April 29, 2016 at 9:33 am

    sObject casting when you use generic sObject and then convert that into a concrete sObject.

    example:-

    Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
    Schema.SobjectType oType = gd.get('account');
    account object_instance = (account)oType.newSObject();

  • Shweta

    Member
    November 6, 2020 at 2:14 pm

    You will need to cast from a generic sobject to a concrete sobject like an opportunity or case or account then do the insert. I've not had to do this before but I have read that you can look at the first 3 letters of objects id or use describe the information to determine what concrete type is being held by the generic. the syntax would be just like you intuited (account)oType.newSobject()

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos