{"id":2144,"date":"2016-11-08T08:46:37","date_gmt":"2016-11-08T08:46:37","guid":{"rendered":"http:\/\/www.greytrix.com\/blogs\/salesforce\/?p=2144"},"modified":"2025-06-10T10:33:54","modified_gmt":"2025-06-10T10:33:54","slug":"creating-sobject-dynamically-by-using-id","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2016\/11\/08\/creating-sobject-dynamically-by-using-id\/","title":{"rendered":"Creating SObject Dynamically by Using Id"},"content":{"rendered":"<p>While working on one of our projects, we faced a challenge where we were supposed to create the object, already existing in the database, dynamically from just an &#8220;Id&#8221;. We had no information other than the Id field of the record. We can use the functions of SObjectType class to create the instance of a SObject (any Standard or Custom object in the Salesforce) dynamically.<\/p>\n<p><strong>Read More:<\/strong> <a href=\"https:\/\/www.greytrix.com\/product\/crm-development\/salesforce-com\">Salesforce Development Services<\/a><\/p>\n<p>Please find below screenshots for the syntax to create the record dynamically:<\/p>\n<div id=\"attachment_2145\" style=\"width: 845px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2016\/11\/Img-1-Code-for-dynamic-record-creation.jpg\" target=\"_blank\" rel=\"noopener noreferrer\"><img fetchpriority=\"high\" decoding=\"async\" aria-describedby=\"caption-attachment-2145\" class=\"size-full wp-image-2145\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2016\/11\/Img-1-Code-for-dynamic-record-creation.jpg\" alt=\"Code for dynamic record creation\" width=\"835\" height=\"427\" \/><\/a><p id=\"caption-attachment-2145\" class=\"wp-caption-text\">Code for dynamic record creation<\/p><\/div>\n<p>You will see in the above code that we have written one method which accepts the first argument as the Id of the record to be updated, the second argument is the string argument that contains the name of the field to be updated, and the third argument being the object type which holds the new value for the field. Within this function, we can use the syntax for dynamic record creation based on Id alone. Once we get the record using the SObjectType, we can populate the field based on the values sent and update the record accordingly into the database. Here is the output of the above code:<\/p>\n<div id=\"attachment_2146\" style=\"width: 444px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2016\/11\/Img-2-Code-output-for-dynamic-record-creation.jpg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" aria-describedby=\"caption-attachment-2146\" class=\"size-full wp-image-2146\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2016\/11\/Img-2-Code-output-for-dynamic-record-creation.jpg\" alt=\"Code output for dynamic record creation\" width=\"434\" height=\"115\" \/><\/a><p id=\"caption-attachment-2146\" class=\"wp-caption-text\">Code output for dynamic record creation<\/p><\/div>\n<p>This is one of the ways how you can get the reference of an already existing record for any SObject dynamically by simply using its Id and perform desired operations on it.<\/p>\n<p><span style=\"font-size: Medium;\"><strong>About Us<\/strong><\/span><br \/>\n<a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a>\u00a0as a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners across the globe. We offers Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that requires apex code incorporation into the Salesforce platform.<\/p>\n<p><a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a>\u00a0has some unique solutions for Cloud CRM such as Salesforce integration with\u00a0<a href=\"https:\/\/www.greytrix.com\/product\/sage-x3\/gumu-x3-salesforce-integration\">Sage Enterprise Management (Sage X3<\/a>),\u00a0Sage Intacct, <a href=\"https:\/\/www.greytrix.com\/product\/sage-100-erp\/gumu-100-salesforce-integration\">Sage 100\u00a0<\/a>and\u00a0<a href=\"https:\/\/www.greytrix.com\/product\/sage-300-erp\/gumu-300-salesforce-integration\">Sage 300 (Sage Accpac)<\/a>. We also offer best-in-class Cloud CRM\u00a0<a href=\"https:\/\/www.greytrix.com\/product\/crm-development\/salesforce-com\">Salesforce customization and development services<\/a> along with services such as Salesforce <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/data-migration-services\">Data Migration<\/a>, <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/integrated-application-development\">Integrated App development<\/a>, <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/custom-development\">Custom App development<\/a> and <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/maintenance-support\">Technical Support<\/a> to business partners and end users.<\/p>\n<p>Greytrix GUMU&#x2122; integration for Sage ERP \u2013 Salesforce is a 5-star app listed on <a href=\"https:\/\/appexchange.salesforce.com\/listingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noopener\">Salesforce AppExchange<\/a>.<\/p>\n<p>For more information, please contact us at\u00a0<a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n<p><strong><span style=\"font-size: Medium;\">Related Posts<\/span><\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2016\/09\/20\/real-time-details-in-gumu-sage-x3-integration-for-salesforce\/\">Real-time details in GUMU SAGE X3 Integration for Salesforce<\/a><\/li>\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2016\/09\/07\/deployment-options-for-changeset\/\">Deployment Options for Changeset<\/a><\/li>\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2016\/08\/30\/save-records-via-lightning-app\/\">Save Records via Lightning<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>While working on one of our projects, we faced a challenge where we were supposed to create the object, already existing in the database, dynamically from just an &#8220;Id&#8221;. We had no information other than the Id field of the record. We can use the functions of SObjectType class to create the instance of a\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2016\/11\/08\/creating-sobject-dynamically-by-using-id\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[15,68,101,367,386,390,913,926,917],"class_list":["post-2144","post","type-post","status-publish","format-standard","hentry","category-salesforce-srv","tag-apex-development","tag-custom-object","tag-dynamic-sobject-new-id","tag-salesforce","tag-salesforce-blogs","tag-salesforce-data-management","tag-salesforce-sobject","tag-salesforce-sobjecttype-class","tag-salesforce-standard-object"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/2144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/comments?post=2144"}],"version-history":[{"count":4,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/2144\/revisions"}],"predecessor-version":[{"id":10889,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/2144\/revisions\/10889"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=2144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=2144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=2144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}