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

    Salesforce Data Loader

    Salesforce Data Loader Guide - Here's All You Need to Know

    Blog in Data, Salesforce Admin

    Data Loader It is a Client Application used for importing and exporting bulk data.  Using it we can Insert, Delete, Update, Upsert, and export the…

    Client Application, CSV File, CSV Format, Custom Objects, Data Loader
    Deepanshi Agarwal Jun 6, 2022
    3,837  Views
    Salesforce Cloud Native

    Comprehensive Guideline On Salesforce Cloud Native

    Blog in Salesforce Cloud Platform

    Cloud computing has been granted accreditation for growing competitiveness by improving flexibility, elasticity, and reducing cost. Companies use cloud-based computing as a means of increasing…

    APIs, Back-end Functionalities, Branded Innovation, Business, Businesses
    Technosip Aug 13, 2021
    4,212  Views
    Aura Components in Salesforce

    Overview of Aura Components in Salesforce | The Developer Guide

    Blog in Salesforce Apex

    Aura The modular, reusable parts of an app are called aura components. From a single line of text to a whole app, they stand for…

    Application Events, AURA, Aura Components, Aura Interfaces, Aura:component Tag
    ashutosh pandey Oct 7, 2022
    5,051  Views

    Popular Salesforce Videos

    Get Started with Salesforce Elevate

    Get Started with Salesforce Elevate

    Video in Salesforce Stories

    Salesforce is a powerful tool to analyze your past fundraising, and monitor your ongoing efforts. In this webinar, we'll start with the fundamentals -- understanding…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Webinar, Salesforce Video
    Prafull Feb 4, 2022
    2,439  Views
    Getting your Customer on Track with Salesforce

    Getting your Customer on Track with Salesforce

    Video in Salesforce Stories

    Hear from Jonathan Gardner, Head of CRM Development First Group, and Lee Holsgrove, Client Adviser IBM as they discuss First Group's transformation bringing together a…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Trailhead, Salesforce Video
    Rupal Kakkar Apr 2, 2021
    1,699  Views
    How to Setup Salesforce Customer Community?

    How to Setup Salesforce Customer Community?

    Video in Salesforce Communities

    Step by step Salesforce tutorial for quickly setting up a Customer Community with Customer Service (Napili) Template.

    Salesforce Tutorial, Salesforce Sales Cloud, Salesforce Administrator, Salesforce Customer Community, Salesforce Community
    Shivam Sisodia Jan 12, 2018
    2,849  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.