{"id":111,"date":"2021-04-07T14:07:43","date_gmt":"2021-04-07T12:07:43","guid":{"rendered":"https:\/\/transferttexei.wordpress.com\/2021\/08\/10\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/"},"modified":"2023-08-18T10:37:44","modified_gmt":"2023-08-18T08:37:44","slug":"save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods","status":"publish","type":"post","link":"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/","title":{"rendered":"Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods"},"content":{"rendered":"\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\r\n<p><strong>EDIT <\/strong>: Despite the exciting title, I stand corrected: Even when Custom Metadata records are retrieved with SOQL Queries, these are not included in the governor limit as documented <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.salesforce_app_limits_cheatsheet.meta\/salesforce_app_limits_cheatsheet\/salesforce_app_limits_platform_apexgov.htm\" target=\"_blank\" rel=\"noopener\">here<\/a>: \u201ccustom metadata records can have unlimited SOQL queries\u201d. Thank you to everyone that came to me to let me know.<\/p>\r\n<\/blockquote>\r\n\r\n\r\n\r\n<p>We all have this kind of project where some part of the application is close to the limit of allowed SOQL queries. Spring \u201921 brings us a simple and easy way to remove some of them, let\u2019s take a look.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Getting Custom Metadata\u00a0records<\/h2>\r\n\r\n\r\n\r\n<p>Using Custom Metadata Types is a great way to store configuration information for your app. It can be configured and deployed easily by an administrator.<\/p>\r\n\r\n\r\n\r\n<p>Using it in your code requires you to retrieve this information. And today the way to do it is just to query the Custom Metadata records like you would do for any regular sObject:<\/p>\r\n\r\n\r\n<script src=\"https:\/\/gist.github.com\/0a1170479ec9208ea8e552360fdd94a0.js\"><\/script>\n\r\n\r\n\r\n<p>This is very easy to do, with only one drawback: it consumes one SOQL, which we all know is <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.salesforce_app_limits_cheatsheet.meta\/salesforce_app_limits_cheatsheet\/salesforce_app_limits_platform_apexgov.htm\" target=\"_blank\" rel=\"noopener\">limited<\/a>.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Getting Custom Metadata records\u2026 starting Spring\u00a0\u201821<\/h2>\r\n\r\n\r\n\r\n<p><a href=\"https:\/\/resources.docs.salesforce.com\/230\/latest\/en-us\/sfdc\/pdf\/salesforce_spring21_release_notes.pdf\" target=\"_blank\" rel=\"noopener\">Spring \u201921 Release Notes<\/a> are a beast of 617 pages, full of great updates. But you can\u2019t miss <a href=\"https:\/\/help.salesforce.com\/articleView?id=release-notes.rn_forcecom_dev_static_accessor.htm&amp;type=5&amp;release=230\" target=\"_blank\" rel=\"noopener\">this one<\/a>: <strong>You can now access Custom Metadata Type records using static methods.<\/strong> Example: without using <strong>any SOQL query<\/strong>.<\/p>\r\n\r\n\r\n\r\n<p>It\u2019s now as easy as this:<\/p>\r\n\r\n\r\n<script src=\"https:\/\/gist.github.com\/80df1bc5bab9680c2dc84ea334395a36.js\"><\/script>\n\r\n\r\n\r\n<p>Notice that you don\u2019t even have to specify the fields you need!<\/p>\r\n\r\n\r\n\r\n<p>Also, as Custom Metadata Types are now part of the application cache, these methods should be faster than their SOQL counterpart.<\/p>\r\n\r\n\r\n\r\n<p>Several methods are available to get the Custom Metadata records you need: <code>getAll()<\/code>, <code>getInstance(recordId)<\/code>, <code>getInstance(qualifiedApiName),<\/code> and <code>getInstance(developerName<\/code>. All of them are documented in the<a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_methods_system_custom_metadata_types.htm\" target=\"_blank\" rel=\"noopener\"> Apex Developer Guide<\/a>.<\/p>\r\n\r\n\r\n\r\n<p>That\u2019s it! As you can see, there are no drawback on this update, it\u2019s just a better way to get Custom Metadata records. So just stop using SOQL queries for this, and update your existing code to benefit from these new methods!<\/p>\r\n\r\n\r\n\r\n<p>Would you want to know more about the other updates made to SOQL and Custom Metadata Types in Spring \u201921, have a look to Nesrine Ould Braham\u2019s blog post <a href=\"https:\/\/blog.texei.com\/release-spring-21-soql-whats-new-4f9521886ec2\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\r\n<p>Want to learn more? Read our article <a href=\"https:\/\/texei.com\/conseils\/anatomie-dune-requete-soql\/\" target=\"_blank\" rel=\"noopener\">Anatomie d\u2019une requ\u00eate SOQL.<\/a><\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>EDIT : Despite the exciting title, I stand corrected: Even when Custom Metadata records are retrieved with SOQL Queries, these are not included in the governor limit as documented here: \u201ccustom metadata records can have unlimited SOQL queries\u201d. Thank you to everyone that came to me to let me know. We all have this kind [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[300],"tags":[306,310],"class_list":["post-111","post","type-post","status-publish","format-standard","hentry","category-advices","tag-apex-en","tag-salesforce-en"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods - Texe\u00ef<\/title>\n<meta name=\"description\" content=\"We all have this kind of project where some part of the application is close to the limit of allowed SOQL queries.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods\" \/>\n<meta property=\"og:description\" content=\"We all have this kind of project where some part of the application is close to the limit of allowed SOQL queries.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/\" \/>\n<meta property=\"og:site_name\" content=\"Texe\u00ef\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-07T12:07:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-08-18T08:37:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/texei.com\/dev\/wp-content\/uploads\/2021\/04\/1_2IPQaCssNjHHRmUQyyKv_Q.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"500\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Fabien Taillon\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/texei.com\\\/en\\\/advices\\\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/texei.com\\\/en\\\/advices\\\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\\\/\"},\"author\":{\"name\":\"Fabien Taillon\",\"@id\":\"https:\\\/\\\/texei.com\\\/#\\\/schema\\\/person\\\/082ce6d13635571cae4161f1d4f5a9a7\"},\"headline\":\"Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods\",\"datePublished\":\"2021-04-07T12:07:43+00:00\",\"dateModified\":\"2023-08-18T08:37:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/texei.com\\\/en\\\/advices\\\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\\\/\"},\"wordCount\":396,\"publisher\":{\"@id\":\"https:\\\/\\\/texei.com\\\/#organization\"},\"keywords\":[\"Apex\",\"Salesforce\"],\"articleSection\":[\"Advices\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/texei.com\\\/en\\\/advices\\\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\\\/\",\"url\":\"https:\\\/\\\/texei.com\\\/en\\\/advices\\\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\\\/\",\"name\":\"Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods - Texe\u00ef\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/texei.com\\\/#website\"},\"datePublished\":\"2021-04-07T12:07:43+00:00\",\"dateModified\":\"2023-08-18T08:37:44+00:00\",\"description\":\"We all have this kind of project where some part of the application is close to the limit of allowed SOQL queries.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/texei.com\\\/en\\\/advices\\\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/texei.com\\\/en\\\/advices\\\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/texei.com\\\/en\\\/advices\\\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/texei.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Advices\",\"item\":\"https:\\\/\\\/texei.com\\\/en\\\/category\\\/advices\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/texei.com\\\/#website\",\"url\":\"https:\\\/\\\/texei.com\\\/\",\"name\":\"Texe\u00ef\",\"description\":\"Turn your IT into Business\",\"publisher\":{\"@id\":\"https:\\\/\\\/texei.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/texei.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/texei.com\\\/#organization\",\"name\":\"Texe\u00ef\",\"url\":\"https:\\\/\\\/texei.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/texei.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/texei.com\\\/dev\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/logo-essai-1.jpg\",\"contentUrl\":\"https:\\\/\\\/texei.com\\\/dev\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/logo-essai-1.jpg\",\"width\":2560,\"height\":1102,\"caption\":\"Texe\u00ef\"},\"image\":{\"@id\":\"https:\\\/\\\/texei.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/texei.com\\\/#\\\/schema\\\/person\\\/082ce6d13635571cae4161f1d4f5a9a7\",\"name\":\"Fabien Taillon\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/texei.com\\\/dev\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/avatar_user_5_1766076207-96x96.png\",\"url\":\"https:\\\/\\\/texei.com\\\/dev\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/avatar_user_5_1766076207-96x96.png\",\"contentUrl\":\"https:\\\/\\\/texei.com\\\/dev\\\/wp-content\\\/uploads\\\/2025\\\/12\\\/avatar_user_5_1766076207-96x96.png\",\"caption\":\"Fabien Taillon\"},\"url\":\"https:\\\/\\\/texei.com\\\/en\\\/author\\\/fabient\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods - Texe\u00ef","description":"We all have this kind of project where some part of the application is close to the limit of allowed SOQL queries.","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:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/","og_locale":"en_US","og_type":"article","og_title":"Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods","og_description":"We all have this kind of project where some part of the application is close to the limit of allowed SOQL queries.","og_url":"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/","og_site_name":"Texe\u00ef","article_published_time":"2021-04-07T12:07:43+00:00","article_modified_time":"2023-08-18T08:37:44+00:00","og_image":[{"width":500,"height":500,"url":"https:\/\/texei.com\/dev\/wp-content\/uploads\/2021\/04\/1_2IPQaCssNjHHRmUQyyKv_Q.jpeg","type":"image\/jpeg"}],"author":"Fabien Taillon","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/#article","isPartOf":{"@id":"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/"},"author":{"name":"Fabien Taillon","@id":"https:\/\/texei.com\/#\/schema\/person\/082ce6d13635571cae4161f1d4f5a9a7"},"headline":"Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods","datePublished":"2021-04-07T12:07:43+00:00","dateModified":"2023-08-18T08:37:44+00:00","mainEntityOfPage":{"@id":"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/"},"wordCount":396,"publisher":{"@id":"https:\/\/texei.com\/#organization"},"keywords":["Apex","Salesforce"],"articleSection":["Advices"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/","url":"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/","name":"Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods - Texe\u00ef","isPartOf":{"@id":"https:\/\/texei.com\/#website"},"datePublished":"2021-04-07T12:07:43+00:00","dateModified":"2023-08-18T08:37:44+00:00","description":"We all have this kind of project where some part of the application is close to the limit of allowed SOQL queries.","breadcrumb":{"@id":"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/texei.com\/en\/advices\/save-some-soql-queries-with-the-spring-21-new-custom-metadata-static-methods\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/texei.com\/"},{"@type":"ListItem","position":2,"name":"Advices","item":"https:\/\/texei.com\/en\/category\/advices\/"},{"@type":"ListItem","position":3,"name":"Save some SOQL queries with the Spring \u201921 new Custom Metadata Static Methods"}]},{"@type":"WebSite","@id":"https:\/\/texei.com\/#website","url":"https:\/\/texei.com\/","name":"Texe\u00ef","description":"Turn your IT into Business","publisher":{"@id":"https:\/\/texei.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/texei.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/texei.com\/#organization","name":"Texe\u00ef","url":"https:\/\/texei.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/texei.com\/#\/schema\/logo\/image\/","url":"https:\/\/texei.com\/dev\/wp-content\/uploads\/2021\/03\/logo-essai-1.jpg","contentUrl":"https:\/\/texei.com\/dev\/wp-content\/uploads\/2021\/03\/logo-essai-1.jpg","width":2560,"height":1102,"caption":"Texe\u00ef"},"image":{"@id":"https:\/\/texei.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/texei.com\/#\/schema\/person\/082ce6d13635571cae4161f1d4f5a9a7","name":"Fabien Taillon","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/texei.com\/dev\/wp-content\/uploads\/2025\/12\/avatar_user_5_1766076207-96x96.png","url":"https:\/\/texei.com\/dev\/wp-content\/uploads\/2025\/12\/avatar_user_5_1766076207-96x96.png","contentUrl":"https:\/\/texei.com\/dev\/wp-content\/uploads\/2025\/12\/avatar_user_5_1766076207-96x96.png","caption":"Fabien Taillon"},"url":"https:\/\/texei.com\/en\/author\/fabient\/"}]}},"_links":{"self":[{"href":"https:\/\/texei.com\/en\/wp-json\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/texei.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/texei.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/texei.com\/en\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/texei.com\/en\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":0,"href":"https:\/\/texei.com\/en\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"wp:attachment":[{"href":"https:\/\/texei.com\/en\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/texei.com\/en\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/texei.com\/en\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}