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

    How do I Choose a Salesforce Implementation Partner?

    Blog in Salesforce Consultant

    Hey there! If you’re reading this, chances are you’re looking to take your business to the next level with Salesforce. That’s a fantastic move! Salesforce…

    Company, Comprehensive Support, CRM Deployment, CRM Implementation, Custom Development
    Emorphis Jun 14, 2024
    767  Views
    collection in salesforce

    Types of Collections in Apex Salesforce | Explained

    Blog in Others

    In Apex, Collection is a group of individual objects represented as a  unit (unit). Sometimes you need to group multiple items in a single unit.…

    Apex Types, Business Requirements, Collection Classes, Collection Type, Collections
    Ayush Aug 10, 2020
    12,851  Views

    Managing Product Bundles Effectively with Salesforce CPQ

    Blog in Salesforce Products

    Salesforce has revolutionized itself in the last 20 years from being one of the SaaS-based products to one of the most preferred and Industry-standard CRM…

    Bundle Layout, Business Functions, Certified Salesforce CPQ Experts, Cloud Software, Commerce
    GS Lab Oct 26, 2022
    2,393  Views

    Popular Salesforce Videos

    Salesforce Multifactor Authentication Webinar

    Salesforce Multifactor Authentication Webinar

    Video in Salesforce customization

    An extra layer of security on your Salesforce org is always worth it. Learn how to safeguard your sensitive Salesforce account information from unauthorized access…

    Salesforce Security, salesforce, Salesforce Org, Salesforce Account, Developers
    360 Degree Mar 16, 2022
    2,035  Views
    Welcome to the New World of Data Collection | Salesforce | Summer Internship

    Welcome to the New World of Data Collection | Salesforce | Summer Internship

    Video in Data, Salesforce Training

    Secure data collection built for your needs. With FormAssembly, your organization can streamline outdated processes and power important business initiatives. To enroll Contact us +91…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce VIdeos, Salesforce Learning
    S2 Jun 23, 2022
    1,897  Views
    What is Validation Rule in Salesforce?

    What is Validation Rule in Salesforce?

    Video in Salesforce Training

    Validation rules verify that the data a user enters in a record meets the standards you specify before the user can save the record. A…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Data, Salesforce Learning
    CRS Apr 12, 2022
    1,659  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.