<?xml version= "1.0" encoding= "utf-8" standalone= "yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>LWC on Spinning Code</title>
    <link>https://spinningcode.org/tags/lwc/</link>
    <description>Recent content in LWC on Spinning Code</description> <generator>Hugo -- 0.157.0</generator>
    <language>en-US</language> <lastBuildDate>Tue, 18 Nov 2025 00:00:00 +0000</lastBuildDate> <atom:link href= "https://spinningcode.org/tags/lwc/feed.xml" rel= "self" type= "application/rss+xml" /> <item>
      <title>LWC Links to Custom Metadata</title>
      <link>https://spinningcode.org/2025/lwc-link-to-metadata/</link>
      <pubDate>
        Tue, 18 Nov 2025 00:00:00 +0000
      </pubDate> <guid isPermaLink="false">https://spinningcode.org/2025/lwc-link-to-metadata/</guid>  <description>How to navigate to Custom Metadata records in a Salesforce LWC, including edit and manage records links.</description> <content:encoded><![CDATA[<p>Now and then I have to work something out that requires a lot of searching around to find all the pieces. When that happens I often write up the instructions on the theory that other people might benefit from the complete answer.</p>
<p>This time I wanted to work out how to create a buttons in a Salesforce Lightning Web Component that allow a user to manage the records.</p>
<p>There are two links that matter in lots of use cases:</p>
<ol>
<li>The edit link for a specific record</li>
<li>The manage records link for custom metadata type to add or delete records</li>
</ol>
<p>The link to a specific record is fairly easy. It&rsquo;s just a simple row action and well supported. The manage records link on the other hand took a bit more research.</p>
<h2 id="custom-metadata-type">Custom Metadata Type</h2>
<p>Obviously, the first thing you need is to <a href="https://trailhead.salesforce.com/content/learn/modules/custom_metadata_types_dec">create your custom metadata type</a>. Exactly what you create isn&rsquo;t important here, the one I was working with was the <a href="https://github.com/acrosman/SalesforceInvalidateEmail/tree/40af241eb9ceaf9f3a018e743cb3ad248235481f/force-app/main/default/objects/Email_Invalidator_Fields__mdt">field list type</a> from my <a href="/2025/salesforce-email-invalidator-tool/">email invalidation tool</a>.</p>
<p>For the purposes of this discussion I will use <code>Your_Metadata_Type__mdt</code> as the placeholder name. Swap in whatever your actual metadata type is called.</p>
<h2 id="the-lwc">The LWC</h2>
<p>Next we create our LWC to help us manage the records. The common use case here is when you&rsquo;re creating a settings page for a custom app or tool. Hopefully one day we&rsquo;ll be able to make these settings pages, but for the foreseeable future they generally need to be a custom app, with a Lightning Record Page, populated with one or more LWCs. Putting all those pieces together is beyond the scope of this article – I am telling you because that is the context of my assumptions.</p>
<p>A basic metadata setting for the LWC should look something like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#75715e">&lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;LightningComponentBundle</span> <span style="color:#a6e22e">xmlns=</span><span style="color:#e6db74">&#34;http://soap.sforce.com/2006/04/metadata&#34;</span><span style="color:#f92672">&gt;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&lt;apiVersion&gt;</span>64.0<span style="color:#f92672">&lt;/apiVersion&gt;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&lt;isExposed&gt;</span>true<span style="color:#f92672">&lt;/isExposed&gt;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&lt;targets&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&lt;target&gt;</span>lightning__AppPage<span style="color:#f92672">&lt;/target&gt;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&lt;/targets&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">&lt;/LightningComponentBundle&gt;</span>
</span></span></code></pre></div><p>We will also need a basic HTML file for this LWC (obviously yours will probably have more elements – mine does):</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#f92672">template</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;<span style="color:#f92672">lightning-card</span> <span style="color:#a6e22e">title</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Metadata Configuration&#34;</span> <span style="color:#a6e22e">icon-name</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;standard:custom_metadata_type&#34;</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">slot</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;actions&#34;</span>&gt;
</span></span><span style="display:flex;"><span>      &lt;<span style="color:#f92672">lightning-button</span> <span style="color:#a6e22e">variant</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;brand&#34;</span> <span style="color:#a6e22e">label</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Manage&#34;</span> <span style="color:#a6e22e">title</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Manage Custom Metadata&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">onclick</span><span style="color:#f92672">=</span><span style="color:#e6db74">{handleManageRecords}</span>&gt;
</span></span><span style="display:flex;"><span>      &lt;/<span style="color:#f92672">lightning-button</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;/<span style="color:#f92672">div</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;<span style="color:#f92672">div</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;slds-m-around_medium&#34;</span>&gt;
</span></span><span style="display:flex;"><span>      &lt;<span style="color:#f92672">template</span> <span style="color:#a6e22e">if:true</span><span style="color:#f92672">=</span><span style="color:#e6db74">{hasData}</span>&gt;
</span></span><span style="display:flex;"><span>        &lt;<span style="color:#f92672">lightning-datatable</span> <span style="color:#a6e22e">key-field</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;Id&#34;</span> <span style="color:#a6e22e">data</span><span style="color:#f92672">=</span><span style="color:#e6db74">{metadataRows}</span> <span style="color:#a6e22e">columns</span><span style="color:#f92672">=</span><span style="color:#e6db74">{columns}</span> <span style="color:#a6e22e">hide-checkbox-column</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;true&#34;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">onrowaction</span><span style="color:#f92672">=</span><span style="color:#e6db74">{handleRowAction}</span>&gt;
</span></span><span style="display:flex;"><span>        &lt;/<span style="color:#f92672">lightning-datatable</span>&gt;
</span></span><span style="display:flex;"><span>      &lt;/<span style="color:#f92672">template</span>&gt;
</span></span><span style="display:flex;"><span>    &lt;/<span style="color:#f92672">div</span>&gt;
</span></span><span style="display:flex;"><span>  &lt;/<span style="color:#f92672">lightning-card</span>&gt;
</span></span><span style="display:flex;"><span>&lt;/<span style="color:#f92672">template</span>&gt;
</span></span></code></pre></div><p>In this example I put the manage button at the top and a simple <a href="https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightning-datatable.html">lightning datatable</a> which will hold one row per metadata record. The button has an <code>onclick</code> action that will call <code>handleManageRecords</code> in the LWC&rsquo;s JavaScript controller. The rows will each have a row action block that triggers <code>handleRowAction</code>.</p>
<h3 id="the-javascript-controller">The JavaScript Controller</h3>
<p>Things start to get more interesting when we get to the actual JavaScript. In fact most of the important work is here.</p>
<p>The JavaScript starts by loading the required modules. Three from Salesforce, and two from our custom Apex Controller (coming up next).</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-JavaScript" data-lang="JavaScript"><span style="display:flex;"><span><span style="color:#66d9ef">import</span> { <span style="color:#a6e22e">LightningElement</span>, <span style="color:#a6e22e">wire</span> } <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;lwc&#39;</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">import</span> { <span style="color:#a6e22e">NavigationMixin</span> } <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;lightning/navigation&#39;</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">getMetaDataRecords</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;@salesforce/apex/MyMetadataController.getMyMetadataRecords&#39;</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">import</span> <span style="color:#a6e22e">getMetadataPrefix</span> <span style="color:#a6e22e">from</span> <span style="color:#e6db74">&#39;@salesforce/apex/MyMetadataController.getCustomMetadataObjectPrefix&#39;</span>;
</span></span></code></pre></div><p>Datatables need to know what columns they are displaying – and it&rsquo;s best to put those in a variable for easy maintenance:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-JavaScript" data-lang="JavaScript"><span style="display:flex;"><span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">COLUMNS</span> <span style="color:#f92672">=</span> [
</span></span><span style="display:flex;"><span>  {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">label</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;Label&#39;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fieldName</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;Label&#39;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">type</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;text&#39;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">sortable</span><span style="color:#f92672">:</span> <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  },
</span></span><span style="display:flex;"><span>  {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">label</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;Developer Name&#39;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">fieldName</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;DeveloperName&#39;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">type</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;text&#39;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">sortable</span><span style="color:#f92672">:</span> <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>  },
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// Plus whatever other fields you need.
</span></span></span><span style="display:flex;"><span>]
</span></span></code></pre></div><p>To make the Edit links work for each row we need to extend the provide <code>NavigationMixIn</code> class we imported above.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-JavaScript" data-lang="JavaScript"><span style="display:flex;"><span><span style="color:#66d9ef">export</span> <span style="color:#66d9ef">default</span> <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">MyMetadataLWC</span> <span style="color:#66d9ef">extends</span> <span style="color:#a6e22e">NavigationMixin</span>(<span style="color:#a6e22e">LightningElement</span>) {
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">columns</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">COLUMNS</span>;
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">metadataRows</span> <span style="color:#f92672">=</span> [];
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// This does the work of actually loading the Custom Metadata.
</span></span></span><span style="display:flex;"><span>  <span style="color:#960050;background-color:#1e0010">@</span><span style="color:#a6e22e">wire</span>(<span style="color:#a6e22e">getMyCustomMetadata</span>)
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">wiredMyCustomMetadata</span>({ <span style="color:#a6e22e">error</span>, <span style="color:#a6e22e">data</span> }) {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (<span style="color:#a6e22e">data</span>) {
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">// Convert map to list
</span></span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">recordList</span> <span style="color:#f92672">=</span> [];
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">recordNames</span> <span style="color:#f92672">=</span> Object.<span style="color:#a6e22e">getOwnPropertyNames</span>(<span style="color:#a6e22e">data</span>);
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">let</span> <span style="color:#a6e22e">i</span> <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; <span style="color:#a6e22e">i</span> <span style="color:#f92672">&lt;</span> <span style="color:#a6e22e">recordNames</span>.<span style="color:#a6e22e">length</span>; <span style="color:#a6e22e">i</span><span style="color:#f92672">++</span>) {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">recordList</span>.<span style="color:#a6e22e">push</span>(<span style="color:#a6e22e">data</span>[<span style="color:#a6e22e">recordNames</span>[<span style="color:#a6e22e">i</span>]]);
</span></span><span style="display:flex;"><span>      }
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">metadataRows</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">recordList</span>;
</span></span><span style="display:flex;"><span>    } <span style="color:#66d9ef">else</span> <span style="color:#66d9ef">if</span> (<span style="color:#a6e22e">error</span>) {
</span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">metadataRows</span> <span style="color:#f92672">=</span> [];
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// Simple helper method to make the templates a little more stable.
</span></span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">get</span> <span style="color:#a6e22e">hasData</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">metadataRows</span> <span style="color:#f92672">&amp;&amp;</span> <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">metadataRows</span>.<span style="color:#a6e22e">length</span> <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">0</span>;
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// The edit action defined here is the really important part for navigating
</span></span></span><span style="display:flex;"><span>  <span style="color:#75715e">// directly to the record you want to update.
</span></span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">handleRowAction</span>(<span style="color:#a6e22e">event</span>) {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">actionName</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">event</span>.<span style="color:#a6e22e">detail</span>.<span style="color:#a6e22e">action</span>.<span style="color:#a6e22e">name</span>;
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">row</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">event</span>.<span style="color:#a6e22e">detail</span>.<span style="color:#a6e22e">row</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (<span style="color:#a6e22e">actionName</span> <span style="color:#f92672">===</span> <span style="color:#e6db74">&#39;edit&#39;</span>) {
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">// Navigate to the record page for editing
</span></span></span><span style="display:flex;"><span>      <span style="color:#66d9ef">this</span>[<span style="color:#a6e22e">NavigationMixin</span>.<span style="color:#a6e22e">Navigate</span>]({
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">type</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;standard__recordPage&#39;</span>,
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">attributes</span><span style="color:#f92672">:</span> {
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">recordId</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">row</span>.<span style="color:#a6e22e">Id</span>,
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">objectApiName</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;Your_Metadata_Type__mdt&#39;</span>,
</span></span><span style="display:flex;"><span>          <span style="color:#a6e22e">actionName</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;edit&#39;</span>
</span></span><span style="display:flex;"><span>        }
</span></span><span style="display:flex;"><span>      });
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">async</span> <span style="color:#a6e22e">handleManageRecords</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">metadataPrefix</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">await</span> <span style="color:#a6e22e">getMetadataPrefix</span>();
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// Navigate to the Custom Metadata Type management page
</span></span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">this</span>[<span style="color:#a6e22e">NavigationMixin</span>.<span style="color:#a6e22e">Navigate</span>]({
</span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">type</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;standard__webPage&#39;</span>,
</span></span><span style="display:flex;"><span>      <span style="color:#75715e">// I&#39;ll explain this bit below.
</span></span></span><span style="display:flex;"><span>      <span style="color:#a6e22e">attributes</span><span style="color:#f92672">:</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#a6e22e">url</span><span style="color:#f92672">:</span> <span style="color:#e6db74">&#39;/lightning/setup/CustomMetadata/page?address=%2F&#39;</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">metadataPrefix</span> <span style="color:#f92672">+</span> <span style="color:#e6db74">&#39;%3Fsetupid%3DCustomMetadata&#39;</span>
</span></span><span style="display:flex;"><span>      }
</span></span><span style="display:flex;"><span>    });
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Currently the NavigationMixIn only provides direct links to Custom Metadata Records, not the manage records page (or the create record form). For the edit links that&rsquo;s just fine: we use the NavigationMixIn&rsquo;s behaviors and off we go. But to get to the Manage Records page we need to create the link itself.</p>
<p>If you go to the page Manage Records page for your Custom Metadata type you&rsquo;ll see the URL is in the form:
<code>/lightning/setup/CustomMetadata/page?address=%2Fm01%3Fsetupid%3DCustomMetadata</code></p>
<p>Salesforce knows which Custom Metadata Type you&rsquo;re talking about from this bit: <code>%2Fm01%3F</code></p>
<p>In URLs anything that starts with <code>%</code> should be followed by a two digit hex code. These are URL Encoded characters (<a href="https://www.w3schools.com/tags/ref_urlencode.ASP">w3Schools has a complete reference</a> if you want it). <code>%2F</code> is <code>/</code> and <code>%3F</code> at the end is <code>?</code>. Between them is the custom metadata type&rsquo;s prefix, in this case <code>m01</code>. This value is Metadata Type and Org Specific: you cannot safely hard-code it. We have to get that from the describe of the type, and that means diving into Apex.</p>
<h3 id="the-apex-controller">The Apex Controller</h3>
<p>To bolt this all together we need two tiny pieces of Apex. The first method will give us the list of records to display, the second gives us that prefix we need for the URL.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-Java" data-lang="Java"><span style="display:flex;"><span><span style="color:#66d9ef">public</span> with sharing <span style="color:#66d9ef">class</span> <span style="color:#a6e22e">MyMetadataController</span> {
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// This gets a list of all the metadata records we plan to display. Pretty standard for LWCs.</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">@AuraEnabled</span>(cacheable<span style="color:#f92672">=</span><span style="color:#66d9ef">true</span>)
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">public</span> <span style="color:#66d9ef">static</span> Map<span style="color:#f92672">&lt;</span>String, Your_Metadata_Type__mdt<span style="color:#f92672">&gt;</span> <span style="color:#a6e22e">getMyMetadataRecords</span>() {
</span></span><span style="display:flex;"><span>    Map<span style="color:#f92672">&lt;</span>String, Your_Metadata_Type__mdt<span style="color:#f92672">&gt;</span> records <span style="color:#f92672">=</span> Your_Metadata_Type__mdt.<span style="color:#a6e22e">getAll</span>();
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> records;
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#75715e">// This provides us with the key prefix for the custom type – needed for the link.</span>
</span></span><span style="display:flex;"><span>  <span style="color:#a6e22e">@AuraEnabled</span>
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">public</span> <span style="color:#66d9ef">static</span> string <span style="color:#a6e22e">getCustomMetadataObjectPrefix</span>() {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> Your_Metadata_Type__mdt.<span style="color:#a6e22e">sobjecttype</span>.<span style="color:#a6e22e">getDescribe</span>()
</span></span><span style="display:flex;"><span>      .<span style="color:#a6e22e">getKeyPrefix</span>();
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>Of course you&rsquo;ll also need test coverage for these functions as well. Everything you need is kicking around in the working example.</p>
<h2 id="working-example">Working Example</h2>
<p>My working example is embedded in the Email Invalidation Tool I built a few months ago and am slowing improving.</p>
<ul>
<li>The <a href="https://github.com/acrosman/SalesforceInvalidateEmail/tree/40af241eb9ceaf9f3a018e743cb3ad248235481f/force-app/main/default/lwc/invalidateEmailFieldsList">complete LWC is here</a>.</li>
<li>The <a href="https://github.com/acrosman/SalesforceInvalidateEmail/blob/40af241eb9ceaf9f3a018e743cb3ad248235481f/force-app/main/default/classes/InvalidateEmailFieldsController.cls">Apex Controller is here</a></li>
</ul>
]]></content:encoded> </item> </channel>
</rss>
