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

    5 Best Sales Cadence Tools for Automating Your Outreach

    Blog in Others

    Today, sales tools are more than simply "nice-to-haves". They assist sales representatives by automating routine processes and increasing overall sales effectiveness to free up time…

    Deals Cadences, Einstein Sales Cloud, Features of Sales Cloud, Implement a Sales Cloud, Sales Cadence
    Twistellar Jan 30, 2023
    1,715  Views
    Leveraging Salesforce’s Complimentary Data Cloud and Tableau Licenses

    Leveraging Salesforce’s Complimentary Data Cloud and Tableau Licenses

    Blog in Salesforce Products

    In the ever-evolving landscape of business, access to valuable data insights and powerful analytics tools is essential for sustainable growth. Salesforce, a leader in customer…

    Business Insights, Competitive Advantage, Complimentary, Cost Efficiency, CRM Solutions
    Kizzy Consulting Apr 11, 2024
    927  Views

    How To Optimize Organizational Operation To Implement Salesforce Lightning Successfully

    Blog in Salesforce customization

    Salesforce Lightning is a new platform, given by Salesforce which is crisper and have many new features and a new interface is introduced for the…

    Implement Salesforce Lightning, Salesforce Classic to Lightning, Salesforce Lightning Development Company
    Louis Aug 2, 2017
    4,429  Views

    Popular Salesforce Videos

    Salesforce Starter Suite and Pro Suite

    Salesforce Starter Suite and Pro Suite

    Video in Salesforce Products

    Selecting and implementing a new customer relationship management (CRM) software can be daunting for a small business. Luckily, Salesforce offers its Starter and Pro Suites,…

    salesforce, CRM, Software, Digital Transformation, Starter Suite
    DB Nov 25, 2025
    280  Views
    Case Management App on Salesforce AppExchange

    Case Management App on Salesforce AppExchange

    Video in AppExchange, Sales

    Is your customer support struggling with customer satisfaction for high service cost? Don't know how to work on right priority cases? Don't worry Algoworks presents…

    Salesforce Case Management, Salesforce Apps, Customer Success, Salesforce Service Cloud Case Management, Customer Engagement
    Algoworks Apr 8, 2019
    2,407  Views
    Understanding Pardot: The Ultimate Guide for Salesforce Admins

    Understanding Pardot: The Ultimate Guide for Salesforce Admins

    Video in Salesforce Products

    In this podcast, Andrea Terrell shares advice for Salesforce Admins on how they can level up their Pardot skills. She has a proven track record…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Admins, Salesforce Video
    Rupal Kakkar Nov 2, 2021
    1,937  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.