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 7 years, 11 months 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 Engage

    Salesforce Engage | Propel Customer Engagement with Relevancy

    Blog in Salesforce, Salesforce Tools

    Marketing without customer engagement is nothing more than an on-air commercial that nobody wants to see. Every day the competition is intensifying, and keeping customers…

    B2B Tool, Business Environment, Customer Engagement, Email Templates, Engage Campaigns
    LevelShift (formerly DemandBlue) Apr 27, 2020
    1,673  Views

    How to get Salesforce coding experience?

    Blog in Coding and Scripting, Salesforce Training

    Well, fitting into a Salesforce developer career need no prior exercise. However, it is recommended and, in fact, better to acquire certain experience so as…

    Career in Salesforce, Coding and Scripting, Developer Forum, Nonprofit Organizations, Real-Time Salesforce Environment
    swetha Dec 6, 2018
    4,842  Views

    Salesforce Leads vs. Contacts: Everything You Need to Know

    Blog in Salesforce

    Understanding the difference between Leads and Contacts is imperative for marketing strategies and effective sales. These two objectives influence tracking prospects, managing relationships, and closing…

    Contact Creation, Contact Engagement, Contact Management, Contact-Based Marketing, Customer Relationship Management
    SP Sep 19, 2024
    805  Views

    Popular Salesforce Videos

    5 Steps to Faster Case Resolution | Salesforce Support

    5 Steps to Faster Case Resolution | Salesforce Support

    Video in Salesforce Stories

    When it comes to filling out a Salesforce case from, the description field and attached files are key to fast routing and resolution. Here are…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Abhishek Feb 11, 2022
    2,005  Views
    4 Benefits of Salesforce Vlocity Communications Clouds

    4 Benefits of Salesforce Vlocity Communications Clouds

    Video in Salesforce Cloud Platform, Salesforce Training

    Vlocity Communications effortlessly collaborate with Salesforce Service Cloud to design a solution to garner personalized and uninterrupted experience for customers throughout their channels. This not…

    Salesforce Training, Salesforce Service Cloud, salesforce, Salesforce Video, Customers
    Cyntexa May 9, 2022
    2,726  Views
    Salesforce Winter '21 Highlights

    Salesforce Winter '21 Highlights

    Video in Salesforce Stories

    Even in these unprecedented times when the world is struggling with a major pandemic that has brought everything to a standstill, Salesforce has strived hard…

    salesforce, User Experience, Salesforce Video, Salesforce Learning, Salesforce Release
    Rupal Kakkar Oct 8, 2020
    1,955  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.