Toggle Side Panel

  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • 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
  • Marketplace
  • Advertise With Us
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • 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
    • Marketplace
    • Advertise With Us
    • 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, 2 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

    application solution

    Popular Salesforce Blogs

    Top Helpful Youtube Channels To Get You Started With Salesforce

    Blog in Salesforce

    Salesforce skills can help advance careers for beginners or for anyone who wants to get into the Salesforce ecosystem. Job seekers can find high-demand, high-paying,…

    Apex Tutorials, App Development Practices, Call Center Management, Certification Courses, Cloud Career Coaching Services
    TechForce Aug 11, 2020
    4,170  Views

    Nine Common Pain Points Solved by Salesforce Revenue Cloud

    Blog in Salesforce Cloud Platform, Salesforce Products

    Revenue, and especially revenue that is trending upwards, is a clear indicator of an organization’s health and potential. However, responding to fluid market shifts and…

    Approval System, Automate Quote Generation, Automated Lead Routing, B2B, B2B Commerce
    DemandBlue Oct 26, 2021
    2,713  Views

    Enhancing Non-Profit Operations with Salesforce Customer Portal

    Blog in Salesforce

    In today's digital age, non-profit organizations strive to leverage technology to streamline their operations and enhance constituent engagement. One powerful tool that empowers non-profits is…

    Attendance Sheets, Automated Receipts, Availability, Benefits, Clear
    CRMJetty Jun 19, 2023
    1,217  Views

    Popular Salesforce Videos

    Salesforce CPQ Tips to Accelerate Sales Cycle

    Salesforce CPQ Tips to Accelerate Sales Cycle

    Video in Sales

    Learn how to accelerate your sales cycle with Salesforce CPQ! Optimize your product catalogue by streamlining listings, removing outdated items, and categorizing products effectively. Automate…

    Salesforce CPQ, CPQ, Selling with Salesforce CPQ, Sales Cycle, Sales with Salesforce CPQ
    Emorphis Sep 5, 2025
    64  Views
    Salesforce Talent Alliance Demo

    Salesforce Talent Alliance Demo

    Video in Salesforce Stories

    Salesforce Talent Alliance connects employers to Salesforce candidates and brings new talent into the ecosystem, emphasizing building a diverse workforce that reflects society around the…

    Salesforce Training, Salesforce Tutorial, Salesforce Video, Salesforce Learning, Ecosystem
    Nauman Aug 20, 2021
    1,143  Views
    Different tools use to code in APEX | APEX Basics | Salesforce Development Course

    Different tools use to code in APEX | APEX Basics | Salesforce Development Course

    Video in Salesforce Apex, Salesforce Training

    Are you aware of the tools that are used for writing codes in APEX? Here are the different tools that you can use to write…

    Salesforce Training, Salesforce Apex, salesforce, Apex, Force.com
    Prafull Jul 7, 2021
    2,594  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

    © 2025 - 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®.

    Try AuditMyCRM - It is a Salesforce CRM Audit tool which comprehensively scans your Salesforce org and gives you the list of errors or warnings you need to take care of.
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.