{"id":1252,"date":"2026-09-04T13:00:00","date_gmt":"2026-09-04T07:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/"},"modified":"2026-09-04T13:00:00","modified_gmt":"2026-09-04T07:30:00","slug":"apex-sobjects-generic-vs-specific","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/","title":{"rendered":"Apex sObjects: Generic vs Specific sObject Types"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex sObjects are how Salesforce records live inside your code. Every Account, Contact or Course__c record you query, create or update in Apex is an sObject. Learning them is the last step of Level 2. It also connects everything you have learned so far to real data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You already know the <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-data-model-explained-objects-fields-and-relationships-for-beginners\/\">Salesforce data model<\/a> and the difference between <a href=\"https:\/\/swapnilzambare.com\/blog\/standard-vs-custom-objects-salesforce\/\">standard and custom objects<\/a>. In the post on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-classes-and-objects-constructors\/\">Apex classes and objects<\/a>, you also saw that sObjects are a special kind of object. Now we will look at them closely. We will compare the specific types, like <code>Course__c<\/code>, with the generic <code>sObject<\/code> type.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Are Apex sObjects?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">An sObject is any object that the Salesforce database can store. In Apex, each record becomes an instance of an sObject type. The type name matches the object&#8217;s API name, such as <code>Account<\/code>, <code>Contact<\/code> or <code>Course__c<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apex gives you two ways to work with them. A specific sObject type, like <code>Course__c<\/code>, knows its exact fields. In contrast, a generic <code>sObject<\/code> variable can hold a record of any type. However, it does not know which fields exist until run time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a simple picture. A specific type is like a labelled folder for &#8220;Course forms&#8221; only, with the fields printed on the front. A generic sObject is like a plain folder that can hold any kind of form. It is more flexible, but you must check what is inside before you use it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Apex sObjects Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Almost all real Apex code reads or writes records. So you will use Apex sObjects in nearly every class and trigger.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Triggers<\/strong> hand you records in <code>Trigger.new<\/code> as a list of sObjects.<\/li>\n\n<li><strong>SOQL queries<\/strong> return lists of sObjects.<\/li>\n\n<li><strong>DML statements<\/strong> like <code>insert<\/code> and <code>update<\/code> take sObjects.<\/li>\n\n<li><strong>Lightning Web Components<\/strong> often receive sObjects from Apex methods.<\/li>\n\n<li><strong>Reusable tools<\/strong>, such as a generic audit helper, use the generic <code>sObject<\/code> type.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How Apex sObjects Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you write <code>new Course__c()<\/code>, Apex creates an in-memory record with empty fields. You set field values with dot notation, such as <code>c.Fee__c = 4500;<\/code>. Nothing reaches the database until you run a DML statement like <code>insert c;<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-1-1024x640.png\" alt=\"Apex sObjects diagram showing create, set fields, insert, update steps\" class=\"wp-image-1250\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The life of an sObject, from new to insert and update.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After an insert, Salesforce fills in system fields such as <code>Id<\/code> and <code>CreatedDate<\/code>. Your variable now points to a saved record. Later changes to the variable stay in memory until you run <code>update<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Specific sObject Types<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A specific type matches one object exactly. The compiler checks every field you use. So if you mistype <code>Fee__c<\/code> as <code>Fees__c<\/code>, the code will not save, and you find the mistake at once.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Course__c course = new Course__c(\n    Name = 'Apex Basics',\n    Fee__c = 4500,\n    Level__c = 'Beginner',\n    Is_Online__c = true,\n    Start_Date__c = Date.today().addDays(14)\n);\ninsert course;\n\nSystem.debug('New course Id: ' + course.Id);\nSystem.debug('Fee with tax: ' + course.Fee__c * 1.18);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The constructor accepts field name and value pairs, which keeps record creation short. Next, <code>insert<\/code> saves the record, and Salesforce sets its <code>Id<\/code>. Then dot notation reads fields directly, with full type checking. The log shows the new Id and a calculated fee.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>USER_DEBUG [9]|DEBUG|New course Id: a015g00000XyZ12AAB\nUSER_DEBUG [10]|DEBUG|Fee with tax: 5310.00<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Relationship Fields<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Specific types also let you follow relationships with dots. For a lookup to a user, you can read <code>course.Owner.Name<\/code> after querying it. For custom lookups, the relationship name ends in <code>__r<\/code>, such as <code>course.Trainer__r.Name<\/code>. We will use these a lot in the SOQL level.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Generic sObject Type<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The generic <code>sObject<\/code> type can hold any record. You cannot use dot notation for custom fields on it. Instead, you use <code>get<\/code> to read a field and <code>put<\/code> to write one, passing the field name as text.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sObject record = new Course__c(Name = 'LWC Basics');\n\nrecord.put('Fee__c', 6000);\nrecord.put('Level__c', 'Intermediate');\n\nDecimal fee = (Decimal) record.get('Fee__c');\nSystem.debug(record.getSObjectType() + ' costs ' + fee);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The variable has the generic type, but the record inside is a <code>Course__c<\/code>. The <code>put<\/code> calls set fields by name, and <code>get<\/code> reads one back. Because <code>get<\/code> returns a generic <code>Object<\/code>, we cast it to <code>Decimal<\/code> with <code>(Decimal)<\/code>. Finally, <code>getSObjectType()<\/code> tells us the real type, so the log prints <code>Course__c costs 6000<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Casting Between Types<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can turn a generic sObject into a specific type with a cast. First, check the type with <code>instanceof<\/code> to avoid errors.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (record instanceof Course__c) {\n    Course__c c = (Course__c) record;\n    System.debug('Online course? ' + c.Is_Online__c);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After the cast, you get dot notation and compile-time checks again. If you cast to the wrong type, Apex throws a TypeException, which is why the <code>instanceof<\/code> check comes first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Useful sObject Methods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every sObject, generic or specific, supports a set of handy methods. The table below lists the ones you will use most.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>What it does<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>get(fieldName)<\/td><td>Reads a field by name<\/td><td>record.get(&#8216;Fee__c&#8217;)<\/td><\/tr><tr><td>put(fieldName, value)<\/td><td>Sets a field by name<\/td><td>record.put(&#8216;Fee__c&#8217;, 500)<\/td><\/tr><tr><td>getSObjectType()<\/td><td>Returns the object type<\/td><td>Course__c<\/td><\/tr><tr><td>clone()<\/td><td>Makes a copy of the record<\/td><td>c.clone(false, true)<\/td><\/tr><tr><td>getPopulatedFieldsAsMap()<\/td><td>Returns fields that hold values<\/td><td>Map of name to value<\/td><\/tr><tr><td>addError(message)<\/td><td>Blocks the save with an error<\/td><td>c.addError(&#8216;Too low&#8217;)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Generic vs Specific Apex sObjects<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares the two styles on the points that matter most in day-to-day code.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Specific type (Course__c)<\/th><th>Generic sObject<\/th><\/tr><\/thead><tbody><tr><td>Field access<\/td><td>Dot notation, c.Fee__c<\/td><td>get and put with text names<\/td><\/tr><tr><td>Compile-time checks<\/td><td>Yes<\/td><td>No, errors appear at run time<\/td><\/tr><tr><td>Holds any object type<\/td><td>No<\/td><td>Yes<\/td><\/tr><tr><td>Readability<\/td><td>High<\/td><td>Lower<\/td><\/tr><tr><td>Needs casting<\/td><td>No<\/td><td>Often, to read typed values<\/td><\/tr><tr><td>Best for<\/td><td>Normal business logic<\/td><td>Reusable tools across objects<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is simple. Use specific types for almost all business logic. Then use the generic type only when one piece of code must work with many objects.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-2-1024x640.png\" alt=\"Apex sObjects diagram comparing specific and generic sObject types\" class=\"wp-image-1251\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Specific vs generic sObject types.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex sObjects Example: A Reusable Helper<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s see where the generic type really helps. Bright Path Tutors wants one helper that fills a default value in any empty field, on any object. It should work for courses today and for other objects later.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class DefaultValueHelper {\n\n    public static Integer fillBlank(List&lt;sObject&gt; records, String fieldName, Object defaultValue) {\n        Integer changed = 0;\n        for (sObject rec : records) {\n            if (rec.get(fieldName) == null) {\n                rec.put(fieldName, defaultValue);\n                changed++;\n            }\n        }\n        return changed;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The method accepts a list of any sObject type, plus a field name and a value. For each record, it checks the field with <code>get<\/code> and fills it with <code>put<\/code> when it is empty. It returns how many records it changed. Because it uses the generic type, it works for <code>Course__c<\/code>, <code>Account<\/code> or any other object.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a call for courses with no level.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Course__c&gt; courses = new List&lt;Course__c&gt;{\n    new Course__c(Name = 'Git Basics'),\n    new Course__c(Name = 'SOQL Basics', Level__c = 'Intermediate')\n};\nInteger filled = DefaultValueHelper.fillBlank(courses, 'Level__c', 'Beginner');\nSystem.debug(filled + ' course updated, first level: ' + courses[0].Level__c);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Only the first course had no level, so the helper fills one field. The log shows <code>1 course updated, first level: Beginner<\/code>. Notice that you can pass a <code>List&lt;Course__c&gt;<\/code> where the method expects a <code>List&lt;sObject&gt;<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating Apex sObjects Dynamically<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes you only know the object name at run time, for example from custom metadata. In that case, use the Schema class to build a record from its name.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String objectName = 'Course__c';\nsObject newRecord = Schema.getGlobalDescribe().get(objectName).newSObject();\nnewRecord.put('Name', 'Dynamic Course');\nSystem.debug(newRecord);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first line holds the API name as text. Then <code>getGlobalDescribe()<\/code> finds the object type, and <code>newSObject()<\/code> creates an empty record of that type. This is an advanced trick, but it shows how far Apex sObjects can go.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex sObjects in Triggers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Triggers are where you meet Apex sObjects first in real projects. Inside a trigger, <code>Trigger.new<\/code> is a list of the records being saved. In a trigger on Course__c, each item is a <code>Course__c<\/code>, so you can use dot notation straight away.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For update triggers, <code>Trigger.oldMap<\/code> holds the old version of each record, keyed by Id. So you can compare old and new values, such as checking whether the fee changed. Because these are normal Apex sObjects, all the methods in this post work on them, including <code>addError<\/code> to block a save.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One rule matters a lot here. In a before trigger, you change fields directly on the records in <code>Trigger.new<\/code>, and Salesforce saves them for you. You do not run <code>update<\/code> on them. In an after trigger, the records are read-only, so you must query and update them in a separate list. We will cover this fully in the triggers level.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex sObjects and Field Access<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex runs in system mode by default, so your code can read fields the user cannot see. That is powerful but risky. When you send Apex sObjects to a component or an outside system, make sure you only include fields the user may view.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The simplest way is to add <code>WITH USER_MODE<\/code> to your SOQL queries. Then Salesforce applies the user&#8217;s field and object permissions automatically. We will explore this in the security level.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Apex sObjects<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Expecting a new record to save on its own. Nothing reaches the database until you run DML.<\/li>\n\n<li>Using a field you did not query. Apex throws an error that the field was not queried, so add it to the SELECT list.<\/li>\n\n<li>Casting without checking. Use <code>instanceof<\/code> before you cast a generic sObject.<\/li>\n\n<li>Mistyping field names in <code>get<\/code> and <code>put<\/code>. The compiler cannot check text, so errors appear only at run time.<\/li>\n\n<li>Using the generic type everywhere. It hides mistakes that the compiler would catch with specific types.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Apex sObjects<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use specific types by default for clear, checked code.<\/li>\n\n<li>Create records with the name and value constructor to keep code short.<\/li>\n\n<li>Save records in lists with one DML statement, never one by one in a loop.<\/li>\n\n<li>Use the generic type only for helpers that truly need to work across objects.<\/li>\n\n<li>Keep field names for <code>get<\/code> and <code>put<\/code> in constants, so typos are easier to spot.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create three Course__c records in a list with different fees, and leave the duration empty on two of them. Then use <code>DefaultValueHelper.fillBlank<\/code> to set <code>Duration_in_Weeks__c<\/code> to 6 where it is empty. Finally, insert the list with one DML statement. Hint: the helper should return 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/langCon_apex_SObjects.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Working with sObjects<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexref.meta\/apexref\/apex_methods_system_sobject.htm\" target=\"_blank\" rel=\"noopener noreferrer\">SObject Class in the Apex Reference Guide<\/a><\/li>\n\n<li><a href=\"https:\/\/trailhead.salesforce.com\/content\/learn\/modules\/apex_database\" target=\"_blank\" rel=\"noopener noreferrer\">Trailhead: Apex Basics and Database<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Apex sObjects are Salesforce records inside your code.<\/li>\n\n<li>Specific types like <code>Course__c<\/code> give dot notation and compile-time checks.<\/li>\n\n<li>The generic <code>sObject<\/code> type holds any record and uses <code>get<\/code> and <code>put<\/code>.<\/li>\n\n<li>Check with <code>instanceof<\/code> before you cast a generic sObject.<\/li>\n\n<li>Nothing saves to the database until you run a DML statement.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You have finished Level 2, Apex Basics. Coming soon: SOQL Basics: Query Records in Apex. That post starts Level 3, where you learn to read data from the database the right way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apex sObjects are how Salesforce records live inside your code. Every Account, Contact or Course__c record you query, create or update in Apex is&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1249,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[8,96],"tags":[98,15,7,97],"swapz_series":[],"class_list":["post-1252","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","tag-apex","tag-beginner","tag-salesforce","tag-salesforce-developer"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apex sObjects: Generic vs Specific sObject Types<\/title>\n<meta name=\"description\" content=\"Apex sObjects explained for beginners: create records in code, read fields, use generic sObject with get and put, cast types and pick the right one.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex sObjects: Generic vs Specific sObject Types\" \/>\n<meta property=\"og:description\" content=\"Apex sObjects explained for beginners: create records in code, read fields, use generic sObject with get and put, cast types and pick the right one.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-04T07:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"Apex sObjects: Generic vs Specific sObject Types\",\"datePublished\":\"2026-09-04T07:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/\"},\"wordCount\":1569,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-sobjects-generic-vs-specific-featured.png\",\"keywords\":[\"Apex\",\"Beginner\",\"Salesforce\",\"Salesforce Developer\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/\",\"name\":\"Apex sObjects: Generic vs Specific sObject Types\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-sobjects-generic-vs-specific-featured.png\",\"datePublished\":\"2026-09-04T07:30:00+00:00\",\"description\":\"Apex sObjects explained for beginners: create records in code, read fields, use generic sObject with get and put, cast types and pick the right one.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-sobjects-generic-vs-specific-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/apex-sobjects-generic-vs-specific-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex sObjects featured image: title card with sObject code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-sobjects-generic-vs-specific\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex sObjects: Generic vs Specific sObject Types\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apex sObjects: Generic vs Specific sObject Types","description":"Apex sObjects explained for beginners: create records in code, read fields, use generic sObject with get and put, cast types and pick the right one.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/","og_locale":"en_US","og_type":"article","og_title":"Apex sObjects: Generic vs Specific sObject Types","og_description":"Apex sObjects explained for beginners: create records in code, read fields, use generic sObject with get and put, cast types and pick the right one.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-04T07:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"Apex sObjects: Generic vs Specific sObject Types","datePublished":"2026-09-04T07:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/"},"wordCount":1569,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-featured.png","keywords":["Apex","Beginner","Salesforce","Salesforce Developer"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/","name":"Apex sObjects: Generic vs Specific sObject Types","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-featured.png","datePublished":"2026-09-04T07:30:00+00:00","description":"Apex sObjects explained for beginners: create records in code, read fields, use generic sObject with get and put, cast types and pick the right one.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/10\/apex-sobjects-generic-vs-specific-featured.png","width":2400,"height":1260,"caption":"Apex sObjects featured image: title card with sObject code"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex sObjects: Generic vs Specific sObject Types"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1252"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1252\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1249"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1252"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}