{"id":2372,"date":"2026-10-17T09:00:00","date_gmt":"2026-10-17T03:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/"},"modified":"2026-11-15T11:30:20","modified_gmt":"2026-11-15T06:00:20","slug":"apex-schema-describe-dynamic-apex","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/","title":{"rendered":"Schema Describe and Dynamic Apex in Salesforce Explained"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Schema Describe lets your Apex ask the org what objects and fields actually exist, while the code is running. So you can build a tool that works on any object, check whether a user may see a field, or read picklist values without hard-coding them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This post builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-sobjects-generic-vs-specific\/\">Apex sObjects<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/dynamic-soql-in-apex-injection\/\">Dynamic SOQL<\/a>. We will build a small field inspector for Bright Path Tutors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Schema Describe?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Schema Describe is a set of Apex classes that return metadata about your org. You can list every object, read an object&#8217;s label and key prefix, list its fields, and read each field&#8217;s type, length and picklist values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a library catalogue. The books are your records. The catalogue tells you which shelves exist, what each one is called and what kind of book sits there, without opening a single book.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Schema Describe Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Hard-coded field names break when an admin renames or removes something. Worse, code that assumes a field exists fails in a different org.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Schema Describe lets you check first. It also powers generic tools, such as a component that renders any object&#8217;s fields, and it is how you check field-level security before showing data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Schema Describe Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">With Schema Describe you start wide and narrow down. Global describe gives every object, then you describe one object, then its field map, then one field.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-diagram-1-1024x640.png\" alt=\"Schema Describe diagram showing the path from global describe down to one field\" class=\"wp-image-2370\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">The path from global describe down to a single field.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Describing an Object<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The shortest route uses the object&#8217;s token directly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Schema.DescribeSObjectResult d = Course__c.SObjectType.getDescribe();\nSystem.debug('Label: ' + d.getLabel());\nSystem.debug('Key prefix: ' + d.getKeyPrefix());\nSystem.debug('Createable: ' + d.isCreateable());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The log shows the user-facing label, the three-character Id prefix and whether this user may create records.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Label: Course\nKey prefix: a01\nCreateable: true<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">The Global Describe<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">When you only have the object name as text, use the global map.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Map&lt;String, Schema.SObjectType&gt; all = Schema.getGlobalDescribe();\nSchema.SObjectType t = all.get('Course__c');\nif (t != null) {\n    System.debug('Found ' + t.getDescribe().getLabel());\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Global describe is heavy, so call it once and reuse the result rather than putting it in a loop.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Describing Fields<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Map&lt;String, Schema.SObjectField&gt; fields =\n    Course__c.SObjectType.getDescribe().fields.getMap();\n\nfor (String apiName : fields.keySet()) {\n    Schema.DescribeFieldResult f = fields.get(apiName).getDescribe();\n    System.debug(f.getLabel() + ' | ' + f.getType() + ' | accessible: ' + f.isAccessible());\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A few lines of that log look like this.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Name | STRING | accessible: true\nFee | CURRENCY | accessible: true\nDuration in Weeks | DOUBLE | accessible: true<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Reading Picklist Values<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;String&gt; levels = new List&lt;String&gt;();\nfor (Schema.PicklistEntry e : Course__c.Level__c.getDescribe().getPicklistValues()) {\n    if (e.isActive()) { levels.add(e.getValue()); }\n}\nSystem.debug(levels);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is how a component shows the current picklist without anyone updating the code when values change.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Schema Describe Access Methods<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These methods answer the security questions you should ask before reading or writing.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Method<\/th><th>Level<\/th><th>Question it answers<\/th><\/tr><\/thead><tbody><tr><td>isAccessible()<\/td><td>Object or field<\/td><td>May this user read it?<\/td><\/tr><tr><td>isCreateable()<\/td><td>Object or field<\/td><td>May this user set it on insert?<\/td><\/tr><tr><td>isUpdateable()<\/td><td>Object or field<\/td><td>May this user change it?<\/td><\/tr><tr><td>isDeletable()<\/td><td>Object<\/td><td>May this user delete records?<\/td><\/tr><tr><td>isQueryable()<\/td><td>Object<\/td><td>Can it appear in SOQL?<\/td><\/tr><tr><td>getType()<\/td><td>Field<\/td><td>What data type is it?<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Static Apex vs Dynamic Apex<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Dynamic Apex builds names at runtime. This table shows the trade-off.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Static Apex<\/th><th>Dynamic Apex<\/th><\/tr><\/thead><tbody><tr><td>Field names<\/td><td>Fixed in code<\/td><td>Built at runtime<\/td><\/tr><tr><td>Compile safety<\/td><td>Full<\/td><td>None<\/td><\/tr><tr><td>Refactor safety<\/td><td>High<\/td><td>Low<\/td><\/tr><tr><td>Flexibility<\/td><td>Low<\/td><td>High<\/td><\/tr><tr><td>Typical use<\/td><td>Business logic<\/td><td>Generic tools<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-diagram-2-1024x640.png\" alt=\"Schema Describe compared with static Apex in Salesforce\" class=\"wp-image-2371\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Static Apex compared with dynamic Apex.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In short, write static Apex by default. Reach for dynamic Apex only when the object or field genuinely is not known until runtime.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Schema Describe Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Bright Path wants a screen that shows any object&#8217;s fields with their types, so admins can check the data model without opening Setup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Return the Field List<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class FieldInspector {\n    public class FieldRow {\n        @AuraEnabled public String label { get; set; }\n        @AuraEnabled public String apiName { get; set; }\n        @AuraEnabled public String dataType { get; set; }\n    }\n\n    @AuraEnabled(cacheable=true)\n    public static List&lt;FieldRow&gt; describe(String objectName) {\n        List&lt;FieldRow&gt; rows = new List&lt;FieldRow&gt;();\n        Schema.SObjectType t = Schema.getGlobalDescribe().get(objectName);\n        if (t == null) { return rows; }\n        for (Schema.SObjectField f : t.getDescribe().fields.getMap().values()) {\n            Schema.DescribeFieldResult d = f.getDescribe();\n            if (!d.isAccessible()) { continue; }\n            FieldRow r = new FieldRow();\n            r.label = d.getLabel();\n            r.apiName = d.getName();\n            r.dataType = String.valueOf(d.getType());\n            rows.add(r);\n        }\n        return rows;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>isAccessible<\/code> check means users never see a field they are not allowed to read.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Build a Safe Dynamic Query<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Dynamic SOQL is where describe really pays off, because you can prove every field exists first.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static List&lt;SObject&gt; safeQuery(String objectName, List&lt;String&gt; wanted) {\n    Schema.SObjectType t = Schema.getGlobalDescribe().get(objectName);\n    Map&lt;String, Schema.SObjectField&gt; fieldMap = t.getDescribe().fields.getMap();\n\n    List&lt;String&gt; safe = new List&lt;String&gt;();\n    for (String w : wanted) {\n        Schema.SObjectField f = fieldMap.get(w.toLowerCase());\n        if (f != null &amp;&amp; f.getDescribe().isAccessible()) { safe.add(f.getDescribe().getName()); }\n    }\n    String soql = 'SELECT ' + String.join(safe, ', ') +\n                  ' FROM ' + t.getDescribe().getName() + ' LIMIT 50';\n    return Database.query(soql);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Only names that came back from describe reach the query string, so a user cannot inject text.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Test It<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;SObject&gt; rows = FieldInspector.safeQuery('Course__c',\n    new List&lt;String&gt;{ 'Name', 'Fee__c', 'Hacker__c' });\nSystem.debug(rows.size() + ' rows, bad field ignored');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The fake field is dropped silently, and the query still runs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These are the describe calls we used and what each returned.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Call<\/th><th>Returned<\/th><\/tr><\/thead><tbody><tr><td>getGlobalDescribe()<\/td><td>Map of all object names<\/td><\/tr><tr><td>getDescribe().getLabel()<\/td><td>Course<\/td><\/tr><tr><td>fields.getMap()<\/td><td>Every field by API name<\/td><\/tr><tr><td>getType()<\/td><td>CURRENCY, STRING and so on<\/td><\/tr><tr><td>isAccessible()<\/td><td>True or false per user<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Schema Describe<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Calling getGlobalDescribe inside a loop, which is slow and heavy.<\/li>\n\n<li>Building dynamic SOQL from raw user text instead of describe results.<\/li>\n\n<li>Forgetting isAccessible, which can expose fields a user should not read.<\/li>\n\n<li>Using field labels as keys, since labels change and are not unique.<\/li>\n\n<li>Assuming the field map keys match your casing, when they are lower case.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Schema Describe<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Call global describe once and cache the result in a static variable.<\/li>\n\n<li>Prefer the direct token, like Course__c.SObjectType, when you know the object.<\/li>\n\n<li>Always check access before reading or writing.<\/li>\n\n<li>Use String.escapeSingleQuotes for any value you must inline.<\/li>\n\n<li>Write static Apex unless the object really is unknown until runtime.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Write a method that takes an object API name and returns only its currency fields. Hint: compare getType() with Schema.DisplayType.CURRENCY.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Schema Describe Interview Questions<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These Schema Describe and Dynamic Apex questions appear in senior developer interviews.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Schema Describe Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is Schema Describe in Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Schema Describe is the set of Apex classes that return metadata about objects and fields at runtime, such as labels, types and access.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: What does getGlobalDescribe return?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It returns a Map of every object API name to its SObjectType token in the org.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: How do you get an object&#8217;s fields?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call getDescribe().fields.getMap() on the SObjectType. Then you get a Map of API name to field token.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: What is a key prefix?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is the first three characters of a record Id, which identify the object. For example, accounts start with 001.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: How do you read picklist values in Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call getDescribe().getPicklistValues() on the field and loop the PicklistEntry list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: What is Dynamic Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is code that decides object or field names while it runs. So the names are not fixed at compile time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: Which method checks read access?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">isAccessible() on the object or field describe result.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: How do you run a query built as text?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With Database.query for a list, or Database.getQueryLocator for large volumes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Intermediate Schema Describe Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: Why is getGlobalDescribe considered expensive?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It builds a map of every object in the org. So call it once and store the result rather than repeating it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: How do you prevent SOQL injection in dynamic queries?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Build field and object names from describe results, use bind variables for values, and escape any text you must inline.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: What is the difference between isAccessible and isUpdateable?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">isAccessible means the user can read it. isUpdateable means the user can change it on an existing record.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: What does getType() return?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Schema.DisplayType value, such as STRING, CURRENCY, REFERENCE or PICKLIST.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: How do you find the parent object of a lookup field?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call getReferenceTo() on the field describe, which returns a list of possible parent types.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: Are describe calls subject to governor limits?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There is no separate describe limit in modern Apex, but the calls still cost CPU time and heap. So cache them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: How do you check whether a field exists?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Look it up in the field map and test for null, rather than referencing it directly in code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: What is stripInaccessible used for?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It removes fields the user cannot access from records or query results, which is an easier alternative to manual checks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Schema Describe Interview Questions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: Scenario: build a component that renders any object. What do you need?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Global describe to validate the object, the field map for columns, access checks per field and a dynamic query built only from describe results.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: How would you cache describe results across a transaction?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Store the maps in a static variable in a utility class, so later calls in the same transaction reuse them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: Why is USER_MODE often better than manual access checks?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because the platform enforces object and field security for the whole query or DML, so you cannot forget a field.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: Scenario: a dynamic query fails only in one customer org. What do you check?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Whether the field exists there, whether the profile can access it and whether a namespace prefix is missing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: How do namespaces affect describe in packages?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Packaged field names carry the namespace prefix. So build names from describe rather than string concatenation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: What is the risk of dynamic Apex during refactoring?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Deleting a field no longer breaks the save, so problems surface only at runtime. Therefore add tests that cover each dynamic path.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q23: How do you list only the required fields on an object?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check isNillable, isDefaultedOnCreate and isCreateable together, since a required field is not nillable and has no default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q24: When should you avoid dynamic Apex entirely?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In normal business logic, where fixed field names give you compile-time safety and clearer code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q25: Is Schema Describe needed for simple triggers?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Usually not. Because you know the object and fields there, static references are clearer and safer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q26: How does Schema Describe help in a managed package?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It lets your code adapt to each subscriber org. So optional fields and different layouts do not break the package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q27: Can Schema Describe tell you about record types?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. The object describe exposes record type infos, so you can list the record types a user can see.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q28: Scenario: an admin renames a field label. Does your describe code break?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not if you key on the API name. However, code that matched on labels will break, which is why labels make poor keys.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q29: How do you keep dynamic code testable?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Write a test per dynamic path with the real object, and assert both the allowed and the blocked cases.<\/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\/apex_dynamic_apex.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Dynamic Apex<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexref.meta\/apexref\/apex_methods_system_fields_describe.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Reference: DescribeFieldResult Class<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_dynamic_soql.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Apex Developer Guide: Dynamic SOQL<\/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>Schema Describe reads object and field metadata at runtime.<\/li>\n\n<li>Global describe is heavy, so call it once and cache it.<\/li>\n\n<li>Access methods let you check security before reading data.<\/li>\n\n<li>Build dynamic SOQL only from describe results.<\/li>\n\n<li>Prefer static Apex for ordinary business logic.<\/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\">Next, we sort lists properly with <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-comparable-comparator-sorting\/\">Comparable and Comparator in Apex<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Schema Describe lets your Apex ask the org what objects and fields actually exist, while the code is running. So you can build a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2369,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[239,8,96],"tags":[68,98],"swapz_series":[],"class_list":["post-2372","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apex-fundamentals","category-salesforce","category-salesforce-developer","tag-advanced","tag-apex"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Schema Describe and Dynamic Apex Explained<\/title>\n<meta name=\"description\" content=\"Learn Schema Describe and Dynamic Apex: read objects and fields at runtime, check access, build dynamic SOQL safely, plus top interview questions.\" \/>\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-schema-describe-dynamic-apex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Schema Describe and Dynamic Apex Explained\" \/>\n<meta property=\"og:description\" content=\"Learn Schema Describe and Dynamic Apex: read objects and fields at runtime, check access, build dynamic SOQL safely, plus top interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-17T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T06:00:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-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=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"Schema Describe and Dynamic Apex in Salesforce Explained\",\"datePublished\":\"2026-10-17T03:30:00+00:00\",\"dateModified\":\"2026-11-15T06:00:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/\"},\"wordCount\":1663,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-schema-describe-dynamic-apex-featured.png\",\"keywords\":[\"Advanced\",\"Apex\"],\"articleSection\":[\"Apex Fundamentals\",\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/\",\"name\":\"Schema Describe and Dynamic Apex Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-schema-describe-dynamic-apex-featured.png\",\"datePublished\":\"2026-10-17T03:30:00+00:00\",\"dateModified\":\"2026-11-15T06:00:20+00:00\",\"description\":\"Learn Schema Describe and Dynamic Apex: read objects and fields at runtime, check access, build dynamic SOQL safely, plus top interview questions.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-schema-describe-dynamic-apex-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-schema-describe-dynamic-apex-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Schema Describe featured image: code editor card with describe call\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-schema-describe-dynamic-apex\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Schema Describe and Dynamic Apex in Salesforce Explained\"}]},{\"@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\\\/10b09224c8bcc562716e86789427592a\",\"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":"Schema Describe and Dynamic Apex Explained","description":"Learn Schema Describe and Dynamic Apex: read objects and fields at runtime, check access, build dynamic SOQL safely, plus top interview questions.","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-schema-describe-dynamic-apex\/","og_locale":"en_US","og_type":"article","og_title":"Schema Describe and Dynamic Apex Explained","og_description":"Learn Schema Describe and Dynamic Apex: read objects and fields at runtime, check access, build dynamic SOQL safely, plus top interview questions.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-10-17T03:30:00+00:00","article_modified_time":"2026-11-15T06:00:20+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"Schema Describe and Dynamic Apex in Salesforce Explained","datePublished":"2026-10-17T03:30:00+00:00","dateModified":"2026-11-15T06:00:20+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/"},"wordCount":1663,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-featured.png","keywords":["Advanced","Apex"],"articleSection":["Apex Fundamentals","Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/","name":"Schema Describe and Dynamic Apex Explained","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-featured.png","datePublished":"2026-10-17T03:30:00+00:00","dateModified":"2026-11-15T06:00:20+00:00","description":"Learn Schema Describe and Dynamic Apex: read objects and fields at runtime, check access, build dynamic SOQL safely, plus top interview questions.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-schema-describe-dynamic-apex-featured.png","width":2400,"height":1260,"caption":"Schema Describe featured image: code editor card with describe call"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-schema-describe-dynamic-apex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Schema Describe and Dynamic Apex in Salesforce Explained"}]},{"@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\/10b09224c8bcc562716e86789427592a","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\/2372","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=2372"}],"version-history":[{"count":1,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2372\/revisions"}],"predecessor-version":[{"id":3207,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/2372\/revisions\/3207"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/2369"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=2372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=2372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=2372"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=2372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}