<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mike Faust on Medium]]></title>
        <description><![CDATA[Stories by Mike Faust on Medium]]></description>
        <link>https://medium.com/@mike.faust?source=rss-c8b3e75af766------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2eE0Ihmxh6ydKrEolrvcYw.jpeg</url>
            <title>Stories by Mike Faust on Medium</title>
            <link>https://medium.com/@mike.faust?source=rss-c8b3e75af766------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:21:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mike.faust/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How MFA Affects Subscriber Support Console Access]]></title>
            <link>https://medium.com/inside-the-salesforce-ecosystem/mfa-affects-subscriber-support-console-access-ebda086482ad?source=rss-c8b3e75af766------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebda086482ad</guid>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[salesforce-tools]]></category>
            <category><![CDATA[appexchange]]></category>
            <category><![CDATA[saas]]></category>
            <category><![CDATA[salesforce]]></category>
            <dc:creator><![CDATA[Mike Faust]]></dc:creator>
            <pubDate>Thu, 05 May 2022 14:03:06 GMT</pubDate>
            <atom:updated>2022-05-05T14:03:06.786Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6QAb6SnWsHAupO_MIVaOUg.jpeg" /></figure><p>Multi-Factor Authentication (MFA) is an easy and effective way to increase user account protection against common security threats like phishing attacks. It does this by adding an additional layer of security to a login process by requiring users to submit two or more pieces of evidence — or factors — to prove they are who they say they are. Effective Feb. 1, 2022, Salesforce contractually requires customers to use MFA for all internal users that log in via the user interface (UI). For more information about the MFA requirement and commonly asked questions, check out this <a href="https://help.salesforce.com/s/articleView?id=000352937&amp;type=1">FAQ</a>.</p><p>There are several different ways to implement multi-factor authentication in an org to meet the MFA requirement. The <a href="https://www.salesforce.com/content/dam/web/en_us/www/documents/guides/mfa-quick-admin-guide.pdf">Multi-Factor Authentication Quick Guide for Admins</a> is a great place to learn more about MFA, the verification methods Salesforce supports, and how to roll it out in your org using change management best practices.</p><p>In accordance with the MFA requirement, the <a href="https://help.salesforce.com/s/articleView?id=release-notes.rn_sfdx_packaging_require_mfa_release_update.htm&amp;type=5&amp;release=236">Spring ’22 release</a> enforces the need for partners to log in to the <a href="https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/packagingGuide/lma_intro.htm">License Management Org (LMO)</a> with MFA to securely access subscriber orgs with the <a href="https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/packagingGuide/lma_subscriber_support_overview.htm">Subscriber Support Console</a>. As the release notes state, this change provides subscribers an added layer of security for managed packages by verifying the identity of users accessing their org. If the partner support user does not authenticate with an MFA high assurance session, they will not be able to access the subscriber org via the Subscriber Support Console.</p><h3>Configuring MFA</h3><p>Let’s walk through one way of enabling MFA in your LMO and common issues you may run into as you try to access the Subscriber Support Console. This method is using the Salesforce Authenticator app, which is downloadable from the Apple App Store and Google Play.</p><ul><li>The first thing you need to do is make sure that Multi-Factor Authentication is set as a high assurance session. You can set this by going to Setup and Session Settings. From there, navigate to the Session Security Levels section and add Multi-Factor Authentication as high assurance.</li></ul><figure><img alt="Picture setting MFA to high assurance for session security levels" src="https://cdn-images-1.medium.com/max/980/0*iNveF72LU0qMbAGE" /></figure><ul><li>The next step you need to take is to require users to authenticate using MFA when they log into the License Management Org to use the Subscriber Support Console. You can enable this by profile or permission set by navigating to the profile or permission sets System Preferences section and click the box for “Multi-Factor Authentication for User Interface Logins”. If you are using permission sets, you’ll need to make sure the permission set is assigned to the user.</li></ul><figure><img alt="Picture of the permission setting that needs to be enabled for users to require MFA" src="https://cdn-images-1.medium.com/max/752/0*0OeUodBc246kjzS_" /></figure><ul><li>Finally, next time your users log in, they will be prompted to set up the authenticator app. The Salesforce login flow will prompt them with the steps as depicted in the image below.</li></ul><figure><img alt="The Salesforce Authenticator screen that is displayed when setting upMFA device on first login" src="https://cdn-images-1.medium.com/max/1024/0*zKGZSVgvZx0SMRj1" /></figure><h3>Subscribers can still require a second MFA</h3><p>As the aforementioned release notes call out, “Starting in Spring ’22, subscribers also have the option of requiring you to complete a second MFA when logging in to their org from the Subscriber Support Console. In this scenario, your login attempt sends an MFA notification to your subscriber, and your login is blocked until your subscriber responds to the notification. By default, the setting that requires a second MFA challenge is disabled. If subscribers require that second layer of security, they must contact Salesforce Customer Support.”</p><p>This means that if customers enable this feature in their org, partners will need to coordinate support timelines with the customer so that the customer can provide the authentication code or approve access via the app.</p><h3>So your users still can’t access the Subscriber Support Console?</h3><p>Once enabled, you may have users experience an error resulting in being unable to log into the subscriber org. Here are a few reasons why this may occur:</p><ul><li>The user’s current session is not logged in as high assurance. This usually happens when the user was already logged in when MFA was set to the user or when MFA was set to high assurance. The user should log out and log back in to establish the high assurance session.</li><li>Multi-Factor Authentication is not set at a high assurance level. Navigate to Setup -&gt; Session Settings -&gt; Session Security Level to verify that Multi-Factor Authentication is set to high assurance (see step one).</li><li>If you are leveraging an SSO Identity Provider’s MFA service, you’ll need to ensure you set that SSO service as high assurance. You can find instructions on how to do that <a href="https://help.salesforce.com/s/articleView?id=sf.mfa_sso_thirdparty_idp.htm&amp;type=5">here</a>.</li></ul><h3>Summary</h3><p>Multi-Factor Authentication is a powerful tool to provide security to customer orgs. Make sure that you enable MFA for your support users so that they can properly support your customers.</p><h3>Need More Help? Check Out These Additional Resources:</h3><p><a href="https://help.salesforce.com/s/articleView?id=release-notes.rn_sfdx_packaging_require_mfa_release_update.htm&amp;type=5&amp;release=236"><em>Require Multi-Factor Authentication for Logins to Subscriber Orgs (Release Update)</em></a></p><p><a href="https://security.salesforce.com/mfa"><em>Multi-Factor Authentication for Salesforce</em></a></p><p><a href="https://help.salesforce.com/s/articleView?id=Salesforce-Multi-Factor-Authentication-FAQ&amp;language=en_US&amp;r=https%3A%2F%2Fwww.google.com%2F&amp;type=1"><em>Salesforce Multi-Factor Authentication FAQ</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebda086482ad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/inside-the-salesforce-ecosystem/mfa-affects-subscriber-support-console-access-ebda086482ad">How MFA Affects Subscriber Support Console Access</a> was originally published in <a href="https://medium.com/inside-the-salesforce-ecosystem">AppExchange and the Salesforce Ecosystem</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Supercharge Your App’s Performance with Free Platform Cache]]></title>
            <link>https://medium.com/inside-the-salesforce-ecosystem/supercharge-apps-performance-free-platform-cache-e253562b4ed8?source=rss-c8b3e75af766------2</link>
            <guid isPermaLink="false">https://medium.com/p/e253562b4ed8</guid>
            <category><![CDATA[tech-experts]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[platform-cache]]></category>
            <dc:creator><![CDATA[Mike Faust]]></dc:creator>
            <pubDate>Thu, 04 Mar 2021 15:02:08 GMT</pubDate>
            <atom:updated>2021-03-04T15:53:03.011Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-LdqKZtEIe2ZTh6e974vxA.png" /></figure><p>Did you know ISVs have the ability to include 3MB of free platform cache? Yes! It’s part of the partner program and, with the Spring ’21 release, ISVs can now include that 3MB of platform cache into their managed packages. Let’s walk through how the free cache provisioning works and what you need to do to take advantage of it.</p><p><em>To learn more about platform cache and its benefits, check out my previous </em><a href="https://medium.com/inside-the-salesforce-ecosystem/leverage-platform-cache-to-reduce-transaction-time-and-increase-customer-satisfaction-cd3616c9c6ee"><em>blog post</em></a><em>.</em></p><h3><strong>How Free Platform Cache Works</strong></h3><p>To leverage platform cache in your managed package, you should define your own namespaced cache partitions in your package and reference them in your code. Besides explicitly including the cache partitions in your managed packages, you’ll need to do the following:</p><ul><li>Allocate the free cache to the desired partitions and upload a new version of your application.</li><li>Pass security review.</li></ul><p><em>NOTE: Existing packages that have already passed security review prior to the Spring ’21 release will automatically provision the cache upon install when the allocation is set in the managed package.</em></p><p>Once your application passes security review, the allocated cache will automatically be provisioned to the assigned partition when you install your package in a customer org. This is for both new installs and upgraded installations.</p><h3><strong>Enabling Free Platform Cache in Your Managed Packages</strong></h3><p>Next, let’s dive into how to enable the free platform cache in both first and second-generation managed packages.</p><p>To enable in your first-generation managed package, you’ll need to do the following:</p><ol><li>In your dev packaging org, navigate to the platform cache partition you want to allocate with the free cache to via Setup -&gt; Platform Cache.</li><li>Click edit next to the partition.</li><li>You’ll see a new category of capacity available called “Provider Free” (highlighted in green box in image below). That’s the amount of free cache capacity you have available to allocate.</li><li>In the session and org cache allocation sections (example highlighted in red), enter the amount of cache you want to provision to the “Provider Free” section. The allocation needs to be in increments of 1 MB and you cannot provision more than what’s available.</li><li>Click Save.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/0*aC4Gx4PQvZo5bzPL" /></figure><p>For second-generation packages, you’ll need to modify the partition metadata. You can do this by following the same steps above in your scratch org and then ensuring you pull the metadata changes. However, I find it easier to modify the metadata manually.</p><p>To modify the metadata directly:</p><ol><li>Open the partition’s <a href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_platformcachepartition.htm">metadata</a> file (.cachePartition-meta.xml extension) in your favorite IDE.</li><li>Under the appropriate cacheType (Organization or Session), enter the amount of cache you would like to associate under the <em>allocatedPartnerCapacity</em> tag.</li><li>Ensure that the <em>allocatedCapacity</em> tag contains the total amount of cache for each allocation (should match the <em>allocatedPartnerCapacity</em> tag).</li><li>Save.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_hn5jwIRUj6JQK-9" /></figure><p><em>NOTE: The allocatedPartnerCapacity property is new as of API v51.0. Please ensure that sourceAPIVersion in your sfdx-project.json is set to at least v51.0 then retrieve your source to access this property.</em></p><p>Once you perform the above steps, you’ll need to create a new version of your application. If you haven’t previously packaged the cache partitions in your managed package, you’ll need to ensure you include them in your package before creating the next version.</p><p><strong>That’s it!</strong> Once your application passes security review, the allocated cache will automatically be provisioned to the assigned partition when you install your package in a customer org. As a reminder, this is for both new installs and upgraded installations.</p><h3><strong>Additional Considerations</strong></h3><p>Here are a few additional considerations about platform cache that may affect your adoption of the free platform cache:</p><ol><li>Platform cache is only available for Enterprise Edition orgs and above. If you try to install your application into a Professional or Essentials Edition org, the package will not install. If you install your package into a Developer Edition org, the package will install, however, it will not contain the free cache allocation.</li><li>Provider Free cache allocations cannot be changed in the subscriber org. If you find that you need to adjust the allocation, you will have to adjust in the next package version of your application.</li><li>If you find a customer that needs more cache allocated to your partitions, the subscriber’s admin can allocate some of their org level cache that they receive as part of the edition of their org.</li><li>Until your package passes security review, you will not be able to test the utilization of the provider free platform cache in a test org. You can, however, allocate trial cache in your Enterprise Edition testing org to ensure you are able to access items from cache.</li><li>You should always test your application without cache allocated to the partition. This will help ensure that you are properly handling cache misses.</li></ol><h3><strong>Summary</strong></h3><p>Platform Cache is a great way to supercharge the performance of your applications. We recommend ISVs take advantage of this amazing benefit.</p><h3><strong>Where to Learn More</strong></h3><p><a href="https://trailhead.salesforce.com/en/content/learn/modules/platform_cache">Platform Cache Basics Trailhead Module</a></p><p><a href="https://help.salesforce.com/articleView?id=release-notes.rn_apex_freeplatformcache.htm&amp;type=5&amp;release=230">Free Platform Cache for Managed Packages</a></p><p><a href="https://help.salesforce.com/articleView?id=sf.data_platform_cache_setup_provider_capacity.htm&amp;type=5">Set Up a Platform Cache Partition with Provider Free Capacity</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e253562b4ed8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/inside-the-salesforce-ecosystem/supercharge-apps-performance-free-platform-cache-e253562b4ed8">Supercharge Your App’s Performance with Free Platform Cache</a> was originally published in <a href="https://medium.com/inside-the-salesforce-ecosystem">AppExchange and the Salesforce Ecosystem</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Utilize Apex Security Enhancements to Reduce Development Time]]></title>
            <link>https://medium.com/inside-the-salesforce-ecosystem/utilize-apex-security-enhancements-reduce-development-time-423890d3dbd5?source=rss-c8b3e75af766------2</link>
            <guid isPermaLink="false">https://medium.com/p/423890d3dbd5</guid>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[tech-experts]]></category>
            <category><![CDATA[appexchange]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[app-development]]></category>
            <dc:creator><![CDATA[Mike Faust]]></dc:creator>
            <pubDate>Mon, 17 Aug 2020 16:01:02 GMT</pubDate>
            <atom:updated>2020-08-17T16:58:22.951Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cs2lxZxY9ENoz03GgETM4w.jpeg" /></figure><p>Building security into your ISV application is an essential part of providing trust to your customers. It’s so important that there is a security review process that every ISV application must pass to be listed on the AppExchange.</p><p>With the <a href="https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_apex.htm?edition=&amp;impact=">Spring ’20 release</a> come two enhancements that drastically reduce the amount of code you have to write while reducing CPU time and heap size: WITH SECURITY_ENFORCED and Security.stripInaccessible().</p><h3>WITH SECURITY_ENFORCED</h3><p>The WITH SECURITY_ENFORCED clause enables field and object-level security checks directly in SOQL select queries in Apex Code, including subqueries and cross-object relationships. This is only needed for queries executed in Apex as Apex runs in system mode whereas queries executed via APIs enforce CRUD/FLS access.</p><p>The security is checked before the query execution. If any fields or objects referenced in the SOQL SELECT query using WITH SECURITY_ENFORCED are inaccessible to the user, a System.QueryException is thrown, and no data is returned. So you’ll still need to handle the error messaging when a user tries to query a field that they don’t have access to.</p><pre>try {<br>  List&lt;Account&gt; accountList = [SELECT Id, Name, AccountNumber, Type  <br>  FROM Account  WHERE Type = ‘Prospect’ WITH SECURITY_ENFORCED ORDER<br>  BY Name];<br>}<br>catch (System.QueryException ex){<br>  throw new AuraHandledException(‘Something went wrong ‘ +<br>  ex.getMessage());</pre><pre>}</pre><p><em>NOTE: To pass security review, the API version of your Apex classes that reference WITH SECURITY_ENFORCED must be v48.0 or higher.</em></p><p>There are some limitations to how WITH SECURITY_ENFORCED works. You are unable to traverse through polymorphic relationships, except for ownerId, createdById, and LastModifiedById fields. For example, you can reference WhatId in your query but not What.Name. The <a href="https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_typeof.htm">TYPEOF</a> statements with an else clause are also not supported.</p><p>Additionally, only fields and objects referenced in the select or from SOQL clauses are checked, not fields in the where or order by. This means that users can execute filtering criteria against fields they may not be able to see. If there are use cases where you want to check the security access of the fields in a where or order by clause, you should leverage our next option item stripInaccessible.</p><h3>Security.stripInaccessible()</h3><p>The Security.stripInaccessible method can be used to strip the fields from the query and subquery results that the user can’t access. This method can also be used to remove inaccessible sObject fields before DML operations to avoid exception and to sanitize sObjects that have been deserialized from an untrusted source.</p><p>Similar to executing schema methods like isAccessible or isCreatable, the access checks are based on the field-level permission of the current user in the context of the specified operation (create, read, update, or upsert).</p><p><em>NOTE: You’ll notice that there is not a delete check with stripInaccessible. When deleting a record, you’ll still need to compose your own isDeletable validation check before executing the delete DML statement.</em></p><p>In this example, we are querying a Contact record with reference to Account fields as a user who doesn’t have access to the Contact.Birthday and Account.Type field.</p><pre>List&lt;Contact&gt; tmpList = [select Id, Name, Email, Birthdate, Phone, AccountId, Account.Name, Account.Type from Contact limit 3];</pre><pre>SObjectAccessDecision securityDecision = Security.stripInaccessible(AccessType.READABLE, tmpList);</pre><p>Security.stripInaccessible returns an instance of the SObjectAccessDecision class. This class contains the list of records with the inaccessible fields to the current user removed. The records are returned in the same order they were submitted into the stripInaccessible method. You can use the getRecords method to access the records.</p><pre>List&lt;Contact&gt; contactList = securityDecision.getRecords();</pre><p>The getModifiedIndexes method of the SObjectAccessDecision class lets you see what records had fields removed while the getRemovedFields method shows you what fields were removed for each object in the operation.</p><pre>System.debug(&#39;modified indexes &#39;  +  securityDecision.getModifiedIndexes());</pre><pre>Debug Output: modified indexes {0}</pre><pre>System.debug(&#39;removed fields &#39; + securityDecision.getRemovedFields());</pre><pre>Debug Output: Removed fields {Account={Type}, Contact={Birthdate}}</pre><p>By combining these methods, you can enforce all-or-none access with regard to field level security. In the scenario below, we created a custom method that creates an account record from an untrusted source (e.g. javascript from lightning web component). If any field is stripped from the record, we prevent the insert from occurring.</p><pre>public static Account createAccount(Account acct) {<br>  SObjectAccessDecision securityDecision =<br>  Security.stripInaccessible(AccessType.CREATABLE, List&lt;Account&gt;<br>  acct);</pre><pre>  //All-or-none logic, so we check if any fields were stripped and<br>  //if so, throw an exception<br>  if (!securityDecision.getModifiedIndexes().isEmpty())<br>  {<br>    throw new AuraHandledException(‘Error Insufficient access to<br>    create account’);<br>  }<br>  insert acct;<br>  return acct;<br>}</pre><h3>Summary</h3><p>Leveraging the WITH SECURITY_ENFORCED and Security.stripInaccessible() methods drastically reduce the amount of code needed to perform CRUD/FLS checks. By not having to execute Schema sObject describes, you’ll also improve the performance of your data access methods.</p><h3>Where to learn more</h3><p><a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_with_security_enforced.htm">Filter SOQL Queries Using WITH SECURITY_ENFORCED</a><br><a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_with_security_stripInaccessible.htm">Enforce Security With the stripInaccessible Method</a><br><a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Security.htm#topic-title">Security Class</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=423890d3dbd5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/inside-the-salesforce-ecosystem/utilize-apex-security-enhancements-reduce-development-time-423890d3dbd5">Utilize Apex Security Enhancements to Reduce Development Time</a> was originally published in <a href="https://medium.com/inside-the-salesforce-ecosystem">AppExchange and the Salesforce Ecosystem</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leverage Platform Cache to Reduce Transaction Time and Increase Customer Satisfaction]]></title>
            <link>https://medium.com/inside-the-salesforce-ecosystem/leverage-platform-cache-to-reduce-transaction-time-and-increase-customer-satisfaction-cd3616c9c6ee?source=rss-c8b3e75af766------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd3616c9c6ee</guid>
            <category><![CDATA[partners]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[tech-experts]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[isvs]]></category>
            <dc:creator><![CDATA[Mike Faust]]></dc:creator>
            <pubDate>Mon, 10 Feb 2020 15:01:01 GMT</pubDate>
            <atom:updated>2020-02-10T15:01:01.367Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ldY9P1cVGjpA0R-DRxBEIA.jpeg" /></figure><p>Performance is an important factor in any application. Ensuring your app performs at the top of its game in all scenarios and situations is critical for customer satisfaction and long-term adoption. This is especially true for ISVs as they create applications that must work well in an org with multiple apps created by both other ISVs and the customers themselves.</p><p>Have you built a really cool application that works great in a controlled test environment, but falls short when installed in a large, enterprise customer’s org? Perhaps transactions run longer than expected? Time to consider platform cache.</p><h3>What is Platform Cache?</h3><p>Platform cache increases the speed at which the data is accessed in a transaction. It further improves performance by distributing cache space to particular namespaces so that cache capacity can’t be stolen by other applications or operations. ISVs can ensure that only Apex executing from their namespace can access the cached value. The best type of data to cache is reused throughout a session, not frequently changing, and expensive to retrieve.</p><p>There are two types of platform cache:</p><ul><li><strong>Session cache</strong> stores data to be reused by an individual user’s session. This data persists for the life of the user’s session (max 8 hours).</li><li><strong>Org cache </strong>stores data that can be reused by any user in the org. Org cache expires when it’s specified time-to-live is reached (max 48 hours).</li></ul><p><em>Bonus: It was announced at Dreamforce ’19 that every ISV application will have access to free platform cache in their package’s namespace. Stay tuned for further updates.</em></p><h3>Let’s Walk Through an Example</h3><p>There may be times where you need to use the Apex Schema describe methods to dynamically determine accessibility of objects and fields to query and then display said fields on a screen. This metadata changes only when an admin goes into setup and is not likely to change often.</p><p>The following example loops through the metadata of ten objects, reads its associated field metadata, and uses that metadata for additional processing.</p><pre>/* In this instance, a wrapper class is used to contain the data that will be used for future processing*/<br>List&lt;WrapperClass&gt; wrapperList = new List&lt;WrapperClass&gt;();<br>List&lt;String&gt; objectNames = new List&lt;String&gt;{&#39;Account&#39;, &#39;Contact&#39;,&#39;Opportunity&#39;, &#39;Task&#39;, &#39;Case&#39;, &#39;Product2&#39;, &#39;OpportunityLineItem&#39;,&#39;Lead&#39;,&#39;CaseTeamMember&#39;,&#39;User&#39;};<br>List&lt;Schema.DescribeSObjectResult&gt; objDescribeList = Schema.describeSObjects(objectNames);<br>for (Schema.DescribeSObjectResult r : objDescribeList) {<br>  WrapperClass wc = new WrapperClass();<br>  List&lt;WrapperClass.FieldData&gt; fieldDataList = new      <br>  List&lt;WrapperClass.FieldData&gt;();<br>  for(Schema.SObjectField fieldType : r.fields.getMap().values()){<br>    Schema.DescribeFieldResult fieldDescribe =  <br>    fieldType.getDescribe();<br>    WrapperClass.FieldData fd = new WrapperClass.FieldData();<br>    fd.fieldName = fieldDescribe.getName();<br>    fd.fieldLabel = fieldDescribe.getLabel();<br>    fd.fieldType = fieldDescribe.getType().name();<br>    fieldDataList.add(fd);<br>  }<br>  wc.objectName = r.getName();<br>  wc.objectLabel = r.getLabel();<br>  wc.fieldMetadata = JSON.serialize(fieldDataList);<br>  wrapperList.add(wc);<br>}</pre><p>Demonstrated in the above example, schema describes can be expensive to execute in every transaction. Meaning, <em>the more objects you describe and the more fields you process, the longer the CPU time. </em>In this example, it takes around 680 milliseconds to execute for 10 objects. For 20 objects, it takes around 950 milliseconds. Imagine the performance impact if you were executing this code against hundreds of objects! (<em>Spoiler Alert: All 730+ objects in a Dev scratch org took around 13,000 milliseconds).</em></p><h3>The Solution? Platform Cache.</h3><p>This type of data is a prime example of when to use platform cache because it’s not dynamic and not frequently changing. To improve performance, we can restructure the code to first check the org cache for the data. We only have to execute the above code when there’s a cache miss (hypothetically, the first transaction of the day).</p><p>It is a best practice to avoid calling the contains(key) method followed by the get(key) method. Since we intended to use the key value in the code below, we get the cache and if the result is null, we then perform the necessary operation to populate the variable and cache.</p><p>Below, the code snippet is refactored to only execute when the data is not found in cache.</p><pre>/*Key used to store cache value. Format in namespace.partition.key*/<br>String cacheKey = &#39;cachepoc1.default.ConfigList&#39;;<br>List&lt;WrapperClass&gt; wrapperList = new List&lt;WrapperClass&gt;();<br>List&lt;String&gt; objectNames = new List&lt;String&gt;{&#39;Account&#39;, &#39;Contact&#39;,&#39;Opportunity&#39;, &#39;Task&#39;, &#39;Case&#39;, &#39;Product2&#39;, &#39;OpportunityLineItem&#39;,&#39;Lead&#39;,&#39;CaseTeamMember&#39;,&#39;User&#39;};<br>/*pull from cache */<br>wrapperList = (List&lt;WrapperClass&gt;)Cache.Org.get(cacheKey);<br>/*If data doesn&#39;t exist in cache, build wrapper class and place into cache*/<br>If (wrapperList == null) {<br>  wrapperList = new List&lt;WrapperClass&gt;();<br>  List&lt;Schema.DescribeSobjectResult&gt; objDescribeList =<br>  Schema.describeSObjects(objectNames);<br>  for (Schema.DescribeSObjectResult r : objDescribeList) {<br>    WrapperClass wc = new WrapperClass();<br>    List&lt;WrapperClass.FieldData&gt; fieldDataList = new<br>    List&lt;WrapperClass.FieldData&gt;();<br>    for(Schema.SObjectField fieldType : r.fields.getMap().values()){<br>      Schema.DescribeFieldResult fieldDescribe =<br>      fieldType.getDescribe();<br>      WrapperClass.FieldData fd = new WrapperClass.FieldData();<br>      fd.fieldName = fieldDescribe.getName();<br>      fd.fieldLabel = fieldDescribe.getLabel();<br>      fd.fieldType = fieldDescribe.getType().name();<br>      fieldDataList.add(fd);<br>    }<br>    wc.objectName = r.getName();<br>    wc.objectLabel = r.getLabel();<br>    wc.fieldMetadata = JSON.serialize(fieldDataList);<br>    wrapperList.add(wc);<br>  }<br>  Cache.Org.put(cacheKey, wrapperList);<br>}</pre><p><em>NOTE: A single cache item has a limit of 100KB and will throw an Cache.ItemSizeLimitExceededException if exceeded, so you’ll need to be thoughtful on how you store data in cache. In this instance, we stored all the data in one cache item. See platform cache limits here. In your development process, you can use the cache diagnostics page in a non-packaging org to examine the cache usage and the compressed size of the cache items. To see this page, enable the user permission “Cache Diagnostics”.</em></p><p>Using org cache instead of session cache allows us to save precious processing time by using the same cached item across all users, not just for an individual user. By refactoring the code, we can now retrieve the data in 10 milliseconds versus the original 680 milliseconds. This reduction in CPU time is compounded across each time the code executes, thus helping you to avoid concurrent apex transaction limits.</p><p>If you want to adopt platform cache as an ISV, you should define your own namespace cache in your package and reference that in your code. This ensures that only your application is leveraging/using the namespaced cache.</p><h3>Summary</h3><p>Platform cache is a great way to reduce CPU time by storing frequently used data that changes infrequently. It’s also a way to ensure your app performs at its very best, which means higher customer satisfaction.</p><h3>Where to Learn More</h3><p><a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_cache_namespace_overview.htm">Platform Cache Overview</a><br><a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_platform_cache_best_practices.htm">Platform Cache Best Practices</a><br><a href="https://trailhead.salesforce.com/en/content/learn/modules/platform_cache">Platform Cache Basics Trailhead Module</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd3616c9c6ee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/inside-the-salesforce-ecosystem/leverage-platform-cache-to-reduce-transaction-time-and-increase-customer-satisfaction-cd3616c9c6ee">Leverage Platform Cache to Reduce Transaction Time and Increase Customer Satisfaction</a> was originally published in <a href="https://medium.com/inside-the-salesforce-ecosystem">AppExchange and the Salesforce Ecosystem</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>