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

    Salesforce Einstein Analytics

    A Trip to the World of Salesforce Einstein Analytics

    Blog in Salesforce Einstein

    Hello Everyone, Welcome to the World of Analytics. Here we begins a trip to the world of Analytics. What's about Analytics? In the glowing era…

    Einstein Analytics, Einstein Analytics Studio, Einstein Discovery, Salesforce Analytics, Salesforce Einstein Analytics
    Archit Jan 9, 2018
    7,775  Views

    The Ultimate Guide to Agentforce: Everything You Need to Know

    Blog in Salesforce

    Imagine having a personal assistant who’s always available and can seamlessly handle various tasks; that’s what Agentforce is. It is like hiring a team of…

    Banking Agent, Channels, Cost Saving, CRM, Customer Experience
    DemandBlue Aug 1, 2025
    203  Views

    6 Ways to Turn Salesforce Marketing Cloud Into Success

    Blog in Salesforce

    Salesforce Marketing Cloud is known to increase the efficiency of your business. As per IDC, Salesforce Marketing Cloud scored 14.1 % more than its rival…

    Artificial Intelligence, Brand Awareness, Brand Design, Business Growth, Campaigns
    Hennery cavil Oct 25, 2022
    1,681  Views

    Popular Salesforce Videos

    Winter 21 - Restrict Access to @AuraEnabled Apex Methods for Authenticated Users

    Winter 21 - Restrict Access to @AuraEnabled Apex Methods for Authenticated Users

    Video in Salesforce Apex, Salesforce Training

    Winter 21 - Restrict Access to @AuraEnabled Apex Methods for Authenticated Users The video explained the following Items: Action items to enable or disable the…

    Salesforce Training, Salesforce Tutorial, Salesforce Lightning, Salesforce Video, Salesforce Learning
    Jogender Nov 5, 2020
    1,412  Views
    Girikon Salesforce Expertise - Salesforce Silver Consulting Partner

    Girikon Salesforce Expertise - Salesforce Silver Consulting Partner

    Video in Salesforce Consultant

    Girikon has experienced and certified Salesforce Consultants are available to meet your entire gamut of Salesforce Implementation, Development, Customization, Integration and Support needs. Get salesforce…

    Salesforce Consultant, Salesforce Consulting Partner, salesforce consultants, salesforce consulting services
    Emily Apr 5, 2018
    1,418  Views
    Subscribe to Dashboards and Reports (Salesforce Lightning Experience)

    Subscribe to Dashboards and Reports (Salesforce Lightning Experience)

    Video in Lightning

    By subscribing to a dashboard or report, you can have it refreshed and waiting in your inbox before the weekly sales meeting, or whenever you…

    Salesforce Training, Salesforce Tutorial, Salesforce Lightning, Salesforce Lightning Experience, Salesforce Learning
    Prafull Jan 19, 2022
    2,879  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.