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

    Choose Salesforce Registered Partners for your Next Project

    Blog in Salesforce

    CRM platforms have emerged as a revolutionary tool for businesses to drive growth, improve customer satisfaction, and streamline operations. Salesforce leads the CRM industry with…

    Apex Transaction, API ID in Salesforce, API in Salesforce, Cache in Salesforce, ISV Partners
    Tech9logy Sep 2, 2024
    447  Views
    change set

    Deploying Process Builder Through Change Set | Salesforce Developer Guide

    Blog in Others, Salesforce

    We can understand process builder as a point-and-click apparatus that lets you effortlessly mechanize if/then trade forms and see a graphical representation of your handle…

    builder, Change Set, Changeset Components, Changeset Page, Child Records
    Anjali Nov 12, 2020
    24,755  Views

    No Code Salesforce and JotForm Integration | Salesforce Guide

    Blog in Salesforce

    One of the most popular cloud-based form automation solutions, JotForm enables users to design and manage web forms as well as track user feedback. It…

    Customization, Developer Org, Digital Experience, Digital Experience Bundle, Digital Websites
    Apphienz Mar 14, 2023
    1,495  Views

    Popular Salesforce Videos

    Dreamforce 2019 - An Overview!

    Dreamforce 2019 - An Overview!

    Video in Others

    Salesforce Dreamforce2019 is scheduled for November 19-22 in San Francisco, California at the Moscone Center. #Dreamforce is one of the largest cloud and SaaS-centric conferences…

    Dreamforce Event, Salesforce Events, Dreamforce 2019, Salesforce Enthusiast, DF 19
    Algoworks Nov 14, 2019
    2,277  Views
    How to Find Queries that Target a Data Extension in Salesforce Marketing Cloud

    How to Find Queries that Target a Data Extension in Salesforce Marketing Cloud

    Video in Salesforce Training

    In this video, Cameron Robert shows how to find SQL queries in Automations that affect a specified Data Extension in Salesforce Marketing Cloud. Key Moments:…

    Salesforce Training, Salesforce Tutorial, Salesforce Marketing Cloud, Salesforce Learning, Data Extension
    Cameron Jul 26, 2022
    1,947  Views
    A Year of Innovation and Growth for Kizzy Consulting - Top Salesforce Partner!

    A Year of Innovation and Growth for Kizzy Consulting - Top Salesforce Partner!

    Video in Salesforce Stories

    2023 was an amazing year for Kizzy Consulting - Top Salesforce Partner! We achieved the status of Salesforce Ridge Partner, completed numerous Salesforce certifications, and…

    Salesforce Partner, Salesforce Consulting Company, salesforce, CRM, payment gateway
    Kizzy Consulting Jun 20, 2024
    654  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®.

    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.