Toggle Side Panel

  • Blogs
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
      • Marketing Cloud ConsultantsMarketing Cloud Consultants
      • Service Cloud ConsultantsService Cloud Consultants
      • Experience Cloud ConsultantsExperience Cloud Consultants
      • Analytics Cloud ConsultantsAnalytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
      • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
      • Health Cloud ConsultantsHealth Cloud Consultants
      • Commerce Cloud ConsultantsCommerce Cloud Consultants
      • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
    • Salesforce Experts by Location
      • USATop Salesforce Consultants in USA
      • IndiaTop Salesforce Consultants in India
      • AustraliaTop Salesforce Consultants in Australia
      • United KingdomTop Salesforce Consultants in UK
      • CanadaTop Salesforce Consultants in Canada
  • Webinars
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Blogs
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
        • Marketing Cloud ConsultantsMarketing Cloud Consultants
        • Service Cloud ConsultantsService Cloud Consultants
        • Experience Cloud ConsultantsExperience Cloud Consultants
        • Analytics Cloud ConsultantsAnalytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
        • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
        • Health Cloud ConsultantsHealth Cloud Consultants
        • Commerce Cloud ConsultantsCommerce Cloud Consultants
        • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
      • Salesforce Experts by Location
        • USATop Salesforce Consultants in USA
        • IndiaTop Salesforce Consultants in India
        • AustraliaTop Salesforce Consultants in Australia
        • United KingdomTop Salesforce Consultants in UK
        • CanadaTop Salesforce Consultants in Canada
    • Webinars
    • Contact Us
    • Discussions
    Close search

    Activity › Forums › Salesforce® Discussions › How to create instance of Sobject dynamically if you don’t know which sobject is going to be instantiated?

    Tagged: Account, Dynamic Apex, Runtime Execution, Salesforce sObject, Tokens in Salesforce

    • Salesforce® Discussions

      How to create instance of Sobject dynamically if you don’t know which sobject is going to be instantiated?

      Posted by Aman on September 22, 2018 at 10:35 PM

      How to create instance of sObject dynamically? Normally the sObject is created like “Account a = new Account();”. But if you are in situation that you don’t know which sObject is going to be instantiated ? Means it will be decided at runtime, how you will handle it in Salesforce?

      shariq replied 8 years, 1 month ago 2 Members · 1 Reply
      • Account
      • Dynamic Apex
      • Runtime Execution
      • Salesforce sObject
      • Tokens in Salesforce
    • 1 Reply
    • shariq

      Member
      September 22, 2018 at 10:35 PM

      public SObject getNewSobject(String t)
      {

      // Call global describe to get the map of string to token.
      Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();

      // Get the token for the sobject based on the type.
      Schema.SObjectType st = gd.get(t);

      // Instantiate the sobject from the token.
      Sobject s = st.newSobject();

      return s;
      }

    Log In to reply.

    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me

    Popular Salesforce Blogs

    Trigger Factory

    TriggerFactory in Salesforce Apex | The Developer Guide

    Blog in Salesforce Apex

    Trigger structures in Apex are something clever. We as a whole realize we need them, we as a whole realize that it is best practice…

    Apex Trigger, Application, Best Practice, Developer Guide, Execute a Custom Setting
    Aditya Feb 26, 2021
    20,442  Views

    Right Salesforce Partner Help You to Grow Your Business with Technology

    Blog in Salesforce Consultant

    As we all are familiar with, consulting firms have become the most reliable method for everyone to get their jobs done quickly. Just throw a little…

    Business, Business Conditions, Business Opportunities, Client References, Consultant Firm
    SaaSnic Sep 21, 2020
    2,316  Views
    Salesforce Features

    8 Best Salesforce Features For Sales Managers 2022

    Blog in Sales, Salesforce

    Salesforce Sales Cloud has the greatest customer base of any Sales CRM in the world. Salesforce has solidified CRM for high-performance sales companies by focusing…

    Client, Corporate Goals, Create Campaign in Salesforce, CRM, CRM Solutions
    Cynoteck May 10, 2022
    3,553  Views

    Popular Salesforce Videos

    5 Things Salesforce Lightning Does Better

    5 Things Salesforce Lightning Does Better

    Video in Lightning

    In this 30-minute recorded webinar, Jamie Grettum talked about her favorite Lightning features, how to set them up, and how to get hands-on experience with…

    Salesforce Lightning, How To Learn Salesforce Lightning, Lightning App Builder, How to Salesforce Lightning Component, Building Lightning Components in Salesforce
    Prafull May 18, 2018
    2,165  Views
    How To Assign Leads in Salesforce | Overview of 3 Main Lead Routing Solutions

    How To Assign Leads in Salesforce | Overview of 3 Main Lead Routing Solutions

    Video in Salesforce Development

    Salesforce offers several options on how to automatically assign incoming leads to a suitable sales manager. But what to choose: out-of-the-box features, external AppExchange app,…

    Lead Assignment rule in Salesforce, Salesforce Lead Assignment Rule, Salesforce Custom Development, Lead Assignment Rule, Lead Routing
    ENWAY Jul 3, 2024
    1,190  Views
    Leads & Opportunities for Lightning Experience - Create and Convert Leads

    Leads & Opportunities for Lightning Experience - Create and Convert Leads

    Video in Lightning

    Learning Objectives After completing this unit, you’ll be able to: Update a record’s stage or status using Path. Update records in the Kanban view. Use…

    Salesforce Training, Salesforce Lightning, salesforce, Trailhead, Salesforce Trailhead
    Vivek Apr 20, 2020
    2,666  Views
    Footer Forcetalks logo

    support@forcetalks.com

    • twitterx

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2023

    Top Salesforce® Bloggers 2023

    Top Salesforce Consultants

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    InsightHub

    Salesforce Blogs

    Salesforce Videos

    Salesforce Groups

    Salesforce Jobs

    © 2026 - Forcetalks ● All Rights Reserved

    Salesforce® is a trademark of Salesforce® Inc. No claim is made to the exclusive right to use “Salesforce”. Any services offered within the Forcetalks website/app are not sponsored or endorsed by Salesforce®.

    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.