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 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

    Unleashing CRM Automation with Agentforce 2.0 and Salesforce Data Cloud

    Blog in Salesforce Cloud Platform

    In 2025, Customer Relationship Management is undergoing a radical transformation—powered by AI and enterprise-grade data orchestration. With the launch of Agentforce 2.0, Salesforce is delivering…

    Dean Sep 5, 2025
    598  Views
    Wrapper Classes in Salesforce | Here's What You Need to Know

    Wrapper Classes in Salesforce | Here's What You Need to Know

    Blog in Salesforce Tutorial

    Apex Wrapper Classes are custom classes in Salesforce that are used to hold one or more primitive data types as members. This allows for encapsulating…

    Apex Wrapper Classes, Browser, Class, Components, Container Class
    Pranjal Feb 10, 2023
    2,385  Views
    SystemVisualforceException - Getting content from within triggers is currently not supported

    System.VisualforceException: Getting content from within triggers is currently not supported

    Blog in Salesforce Apex

    System.VisualforceException: Getting content from within triggers is currently not supported (Salesforce Visualforce Error Notification) ---------------------------- Hi All, Recently I was working on a task in…

    getContentAsPdf(), Salesforce Apex, Salesforce Apex Code, Salesforce Apex Page, Salesforce Apex Trigger
    arpit Apr 2, 2018
    15,813  Views

    Popular Salesforce Videos

    Build Better with Salesforce Architects

    Build Better with Salesforce Architects

    Video in Salesforce Training, Salesforce Admin

    A Salesforce Architect is a trusted advisor and leader who partners with business stakeholders and executives to design a vision and architecture for a solution…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Vivek Apr 28, 2022
    1,981  Views
    Migrating from Salesforce NPSP to Nonprofit Cloud

    Migrating from Salesforce NPSP to Nonprofit Cloud

    Video in Salesforce Products

    The Salesforce Nonprofit Success Pack (NPSP) is a longstanding managed package with a user-friendly constituent management application and fundraising tool. However, Salesforce is pivoting nonprofit…

    salesforce, CRM, NPSP, Nonprofit Success Pack, Digital Transformation
    DB Nov 25, 2025
    287  Views
    Salesforce Health Cloud – Creating Patient Relationships Not Records

    Salesforce Health Cloud – Creating Patient Relationships Not Records

    Video in Salesforce Cloud Platform

    Unfortunately, the gruesome truth facing the world today is the ever increasing pressure of diseases due to chronic disorders, pollution, growing age, and definitely increasing…

    Salesforce Products, Salesforce Security, Cloud Computing, Salesforce Cloud, Salesforce Community
    Algoworks Jan 12, 2018
    2,823  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.