<?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 Sagar R on Medium]]></title>
        <description><![CDATA[Stories by Sagar R on Medium]]></description>
        <link>https://medium.com/@rsagarpro?source=rss-d7b1e100739e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*L38ILHFWdzfEmCSa</url>
            <title>Stories by Sagar R on Medium</title>
            <link>https://medium.com/@rsagarpro?source=rss-d7b1e100739e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:55:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rsagarpro/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[Security in APEX]]></title>
            <link>https://medium.com/@rsagarpro/security-in-apex-cf1fda14e514?source=rss-d7b1e100739e------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf1fda14e514</guid>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[sales-development]]></category>
            <category><![CDATA[salesforce]]></category>
            <dc:creator><![CDATA[Sagar R]]></dc:creator>
            <pubDate>Fri, 20 Jun 2025 14:22:50 GMT</pubDate>
            <atom:updated>2025-06-25T18:09:22.500Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>Record Level security:</em></strong> When we define a keyword (<strong><em>omitted sharing/ </em>without sharing/ with sharing/inherited sharing</strong>) on the APEX class will handle the record level security.<br>Note: I think in this way, sf has defined the naming convention in a way that the name will define everything its that simple. Just think of any keyword in sf that will give you the 60% of the answer. <br>Let’s take the same analogy for these keywords.</p><p><a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_enforce_usermode.htm">Salesforce Developers</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r9ffPBXy4mCYCoPs7f-wGg.png" /></figure><p><strong><em>omitted sharing</em></strong> : There will not be any keyword defined in the class.</p><pre>//* This is not the sf BP to define a class without any keyword.<br>public class NoSharingExample{<br>  <br>  public void fetchAccounts() {<br>    //* Ignores the user&#39;s sharing rules<br>    List&lt;Account&gt; accounts = [SELECT Id, Name FROM Account LIMIT 10];<br>  }<br>}</pre><p>The above code will always runs on the system mode without considering user’s record sharing rules, it will give the access to all the records in the org.<br><strong><em>without sharing: </em></strong>We will explicitly say the class need to be run without any sharing rules. It will run always system mode. Similar to omitted sharing.</p><pre>//* This considered as BP by sf that we are explicitly saying what context the class must run.<br>public without sharing class WithOutSharingExample{<br>  <br>  public void fetchAccounts() {<br>    //* Ignores the user&#39;s sharing rules<br>    List&lt;Account&gt; accounts = [SELECT Id, Name FROM Account LIMIT 10];<br>  }<br>}</pre><p><strong><em>with sharing: </em></strong>we say the class must run in sharing context of the user who is running the APEX class.</p><pre>//* class must be running on user&#39;s context with record sharing mode.<br>public with sharing class WithSharingExample{<br>  <br>  public void fetchAccounts() {<br>    //* Respects the user&#39;s sharing rules<br>    List&lt;Account&gt; accounts = [SELECT Id, Name FROM Account LIMIT 10];<br>  }<br>}</pre><p><strong><em>inherited sharing:</em></strong> It will run the context of the called class if it is without sharing system mode, else with sharing then user mode.<br>Name says it has to inherited the behavior of the calling class that simple.</p><pre>//* class must be running on called class context.<br>public inherited sharing class InheritedSharingExample{<br>  <br>  public void fetchAccounts() {<br>    //* Respects the called class context.<br>    List&lt;Account&gt; accounts = [SELECT Id, Name FROM Account LIMIT 10];<br>  }<br>}</pre><p>Note: Through explicit declaring the keyword on the class level will always takes the precedence, its like hardcoding the class to run in which context.<br>To avoid ambiguity, explicitly declaring sharing keyword on the class.</p><p><strong><em>SOQL Field Level Security:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U5N1KhiXO9bA5lZarQk-YQ.png" /><figcaption>FLS on SOQL</figcaption></figure><p>DML to enforce the user mode to insert the records.</p><pre>public without sharing class DmlWithUserContext {<br>  <br>  public static void findDmlUserMode() {<br>  <br>    Account acc = new Account(Name = &#39;DML UserMode&#39;, Industry = &#39;Education&#39;);<br>    //* as user key word will do DML as per the user security defind on the object<br>    insert as user acc;<br>  }<br>} </pre><p>Now to bypass the above security modes (FLS, Object) on DML and SOQL we have Security class where it methods will strip you off the fields that user does not have access to. Like code runs on the user’s context and will remove the fields before performing DML without any exceptions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*fMFlS4qxcsoAdpCsXazZHw.png" /><figcaption>Security Class Usage</figcaption></figure><p>full security class details:</p><p><a href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Security.htm">Salesforce Developers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf1fda14e514" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom Labels vs Custom Settings vs Custom Metadata.]]></title>
            <link>https://medium.com/@rsagarpro/custom-labels-vs-custom-settings-vs-custom-metadata-669bbde8f714?source=rss-d7b1e100739e------2</link>
            <guid isPermaLink="false">https://medium.com/p/669bbde8f714</guid>
            <category><![CDATA[sales-development]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <dc:creator><![CDATA[Sagar R]]></dc:creator>
            <pubDate>Wed, 18 Jun 2025 17:12:14 GMT</pubDate>
            <atom:updated>2025-06-18T17:12:14.007Z</atom:updated>
            <content:encoded><![CDATA[<p>Before we get into these lets understand what is metaData vs data in sf.<br><em>Data:</em> It is the information what we store into the sf, like records and its field values.<br>The data can be queried using SOQL like running a query on the salesforce objects.</p><pre>SELECT Id, Name, Industry FROM Account </pre><p><em>Metadata:</em> To hold this data SF has a structure like standard and custom objects. On this object we store real data.<br>But on metadata we can’t so we need some special tools 🪛which enables us to query on the metadata (postman, workbench, salesforce inspect etc..,) who has a capability to enable to the tooling / metadata api’s.<br>Metadata records can’t be inserted using apex DML operations.</p><p>Note: keep it in mind that sf is all about objects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*MsuV2WUCXtcn_eNctW1DQw.png" /><figcaption>To find the fields on the metadata/we can find that by set up too but this like dev skills.</figcaption></figure><p><strong><em>Custom Labels:</em></strong><em> </em>These are not standard sObjects, so we can’t query or create a new instance to deal with any DML operations.<br>All these custom labels are stored in the cache memory where we no need to query then so we use label class below.</p><p><a href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Label.htm">Salesforce Developers</a></p><pre>//* How to get the custom label information<br>System.Label.lable_ApiName;</pre><p>Now let’s ask why we need this : majorly to avoid any hard coding the values in apex/flows/formulas/vf pages/lwc we use these values to refer them. So that in future if any values that need to changed then we just update them in the set up. More flexibility to tweet the behavior of the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LhO598B5La0Y9tr7BO9y5Q.png" /><figcaption>Custom Labels creation</figcaption></figure><p>Some special features of custom labels:<br>1. Supports multi lingual feature in an application, where users to change/translate text values into any language.<br>2. This can be done through setting up the user with the respective language in Translation settings.<br>3. Only one value can be stored and its just like a field and its value.<br>4. Not visible in test classes and can’t use in validation rules.<br>5. Can be deployable.</p><p><em>Custom Settings: </em>These are more than custom objects but less than custom metadata. Here we store metadata like configuration etc.., (structure that defines the sf can be considered as metadata).</p><p>Types: <br>1. List custom setting : These are no longer used as we have custom metadata. So for now just know that we have this.<br>2. Hierarchy custom setting: This will help us to define data base on profile/users. <br>Ex: if you are a amazon prime member your discount is = 50%.<br>if you are a regular non-prime member your discount is = 10%.<br>This feature will help us to segregate the code or logic behavior based on the profile/ users.<br>Ex: real use case — system admin user and normal user where system admins should able to bypass the validation rule but for others the validation rule should be fired.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*-9mGn11sy3N29tha_A5nDA.png" /><figcaption>Defined custom setting object.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I_A4-VM2OuAR3gUIiK49_A.png" /><figcaption>Created a check box field</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a3mfF_gI8W7T9AZ9UHLGIw.png" /><figcaption>We have two records 1. system admin 2. regular user</figcaption></figure><p>Now i have check the value to true for regular user and false for system admin, now we can use this in the validation rules to check the condition to fire or bypass it based on the profile/user basis.<br>We can use below methods to get the values of the custom setting data.</p><p><a href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_custom_settings.htm">Custom Settings Methods</a></p><p><strong><em>Advantages :</em></strong><br>1. Can store multiple values, no need to query, resides in cache memory fast access.<br>2. Profile/User bases values can be stored.<br><strong><em>Limitations:</em></strong><br>1. Objects counts agains total custom objects limit in org.<br>2. Only metadata can be migrated but not the records &amp; its values (need to import and export the records by using CSV files or Using change sets, vs code + SFDX or Metadata API).<br>3. No relationship fields to connect the records(lookup).<br>4. Can’t be accessed into test classes.</p><p><strong><em>Custom Metadata :</em></strong> These are more than custom setting were we can create our own setup objects who’s data is metadata rather than data.<br>These also resides into cache memory but we must query the records first time.<br>The second time when you query the records they don’t count under SOQL limits &lt; 100 with in the <strong>same transaction</strong> because sf fetches the data from cache memory.<br>If you need to by pass the cache, use clearQueryCache() or execute in the new transaction.<br><strong><em>Advantages:</em></strong><br>1. Highly configurable &amp; easy migration to higher orgs.<br>2. We can get the records and entire object details to deploy.<br>3. We can create validation rules, page layouts.<br>4. Look up relationship to custom metadata.<br>5. Visible in test classes, used in formula fields.<br><strong><em>Disadvantages:</em></strong><br>1. We can’t create the tabs.<br>2. Need to query to fetch the data first time in a transaction.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=669bbde8f714" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best Practices of SOQL]]></title>
            <link>https://medium.com/@rsagarpro/best-practices-of-soql-a7f6ff39dcc5?source=rss-d7b1e100739e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7f6ff39dcc5</guid>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[sales-development]]></category>
            <category><![CDATA[soql]]></category>
            <dc:creator><![CDATA[Sagar R]]></dc:creator>
            <pubDate>Tue, 17 Jun 2025 18:36:44 GMT</pubDate>
            <atom:updated>2025-06-17T18:36:44.789Z</atom:updated>
            <content:encoded><![CDATA[<p>As we know that SF does don’t have any database to store the data. We lean to oracle database to store the sf data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cM49eFfdXyoIjFw_JDRh6A.png" /></figure><p>Running on multi tenant architecture we can’t monopolize the resources so SF forces us to follow under Governor Limits.</p><p>Now considering above we need to run the query in optimized way to fetch the records as it pass through SF query optimizer to determine the query is abide with Governor Limits to give optimal results.<br>In out org developer console we have a hidden tool called query plan, which will determine how much the cost of your query is ran on SF. We must always keep it &lt; 1 to make a query optimized one as per SF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*Xaxx4Kwk0Fmo7r3Ad21tPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*Or5m42lSL1FjrooWbLOMig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*zq7P9MCxCSklEtEpDTu6xQ.png" /><figcaption>With out any index</figcaption></figure><p><strong><em>Enable Query Plan </em></strong>: Dev console &gt; Preferences &gt; Enable Query Plan = True &gt; you will see under the query button a new button Query Plan enabled.<br>Try running a query and see what is the cost of the query?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*sMAyXDUbTlMUMO-t8bngBQ.png" /><figcaption>using indexed fields the cost &lt; 1</figcaption></figure><p><strong><em>Note:</em></strong> when we speak about SF just keep in mind that every thing in sf is like objects (data stored). To know which fields on the object are indexed can be know by “FieldDefnetion” object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F4CaWZTq6XEYj_uQAVJPNQ.png" /><figcaption>To know which field in the object is indexed</figcaption></figure><p>BP to be followed while writing SOQL:<br>1. Always keep query selective.<br>2. Use indexed fields to make query selective. By default (LastModifiedDate &amp; SystemModStmp) fields are indexed fields in all objects.<br>3. Only query the required fields not all (to avoid heap size exception).<br>4.👍 rule no SOQL inside for loop.<br>5. Use LIMIT key to 50000 to avoid governor limits.<br>6. Use of WITH USER_MODE to enforce the user context security.<br>7. ❌ no selective query like using null, !=, NOT LIKE or EXCLUDES, LIKE.<br>8. ❌ Avoiding querying on formulaFields.</p><pre>1. SELECT CaseNumber FROM case WHERE Status IN (&#39;Open&#39;, &#39;In Progress&#39;) WITH USER_MODE LIMIT 50000;</pre><p><strong><em>Note:</em></strong> <br>1.when you try to search 🔎 entire table it will take more time ⏱️ , so simple only try to field the records what we need put that in the query 😎 don deal.<br>2. Assume in your phone you have trash 🗑️ bing where you have deleted some photos to keep your phone fast you try to remove then clt+alt+delete🧹 that will make your phone smooth running. Same applies to SF data table. So try delete records in the recycle bin then you can run SOQL fast it will improve your performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7f6ff39dcc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SF Polymorphic Queries]]></title>
            <link>https://medium.com/@rsagarpro/sf-polymorphic-queries-de3ab24400cb?source=rss-d7b1e100739e------2</link>
            <guid isPermaLink="false">https://medium.com/p/de3ab24400cb</guid>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[soql]]></category>
            <dc:creator><![CDATA[Sagar R]]></dc:creator>
            <pubDate>Tue, 17 Jun 2025 01:49:25 GMT</pubDate>
            <atom:updated>2025-06-17T01:49:25.158Z</atom:updated>
            <content:encoded><![CDATA[<p>The SF relationship where one object is referenced with multiple objects. Like for an instance Task object got who fields (WhoId and WhatId) where they are looking up for more than one objects.<br>WhoId: Refers to people so, it will be Contact and Lead objects.<br>WhatId: Other than Contact and Lead objects all other objects we can say.</p><pre>//* SOQL together WHO and WHAT :<br>SELECT Id, WhoId, WhatId,<br>      TYPEOF Who<br>            WHEN Contact<br>            THEN Id, Name, LastName, Phone<br>            WHEN Lead<br>            THEN Id, Name, Phone, Email, Rating END,<br>      TYPEOF What<br>            WHEN Account<br>            THEN Id, Name, Industry, Rating END<br>FROM Task</pre><p><em>Understand the Query :</em><br>1. Let’s build the basic skeleton : SELECT Id, WhoId, WhatId FROM Task<br>2. As we have multiple object that are associated with two fields so lets build that : <br>TYPEOF Who<br> WHEN Contact<br> THEN contact_fields END,</p><p>TYPEOF What<br> WHEN Account<br> THEN Account_fields END</p><p><em>Note:</em> We can use all other WHERE clause how we use in the SOQL and We can even fetch the parent records related fields as we do Account.Name etc..,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_GxdRaBd97aByp9FEsDJg.png" /><figcaption>Parent fields to query and use of WHERE clause.</figcaption></figure><p>Where we can use this polymorphic Query to know what instance of objects that are delts/associated with task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lgh4d-QTGSc_6ptpLu9QWQ.png" /><figcaption>use of insatcneof method to know what obejcts associated with.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de3ab24400cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Power of Aggregate Quires in SOQL]]></title>
            <link>https://medium.com/@rsagarpro/power-of-aggregate-quires-in-soql-e1400b68abe3?source=rss-d7b1e100739e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1400b68abe3</guid>
            <category><![CDATA[salesforce-soql]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[soql]]></category>
            <category><![CDATA[async-soql]]></category>
            <dc:creator><![CDATA[Sagar R]]></dc:creator>
            <pubDate>Sun, 15 Jun 2025 15:51:42 GMT</pubDate>
            <atom:updated>2025-06-15T15:51:42.924Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mY2GmPGkrn5OSMW7pk1zFg.png" /></figure><p><strong><em>Aggregate Query:</em></strong> These queries has functions/method that are numeric methods run on a particular field to return the statistics about then values of the field for the given set of records. As the performance of this query is high.<br><strong><em>Functions :</em></strong><br>COUNT(), COUNT(field_name), AVG(numeric_field), SUM(numeric_field).</p><pre>//* COUNT() - This will return the number of records that re meeting the SOQL criteria.<br><br>Integer totalAccounts = [SELECT COUNT() FROM Account];<br>System.debug(&#39;Total Accounts :&#39; + totalAccounts);<br><br>//* COUNT(Id) - This is bp to know how many records we have got, as Id always will be there for any record.<br><br>List&lt;AggregateResult&gt; totalNumberOfRecordsWithValue = [SELECT COUNT(Id) FROM Account];<br>System.debug(&#39;Total number of records with value :&#39; + totalNumberOfRecordsWithValue);<br><br>//* SUM(Amount)<br><br>List&lt;AggregateResult&gt; sumOftheOpportunities = [SELECT SUM(AMOUNT) FROM Opportunity];<br>System.debug(&#39;Sum of the Opps:&#39; + sumOftheOpportunities);<br><br>//* AVG(Amount)<br><br>List&lt;AggregateResult&gt; avgOpportunity = [SELECT AVG(AMOUNT) FROM Opportunity];<br>System.debug(&#39;Average of the Opps:&#39; + avgOpportunity);</pre><p><em>IMP Consideration:</em></p><p>1. The query results are group of records so the return type is List&lt;AggregateResults&gt; class.<br>2. If we need to filter the aggregate results we can use HAVING key word.<br>3. We can group the records by GROUP BY.<br>4. We can use WHERE clause as usually to filter the criteria.<br>5. Taking help of alise names we can loop through the records.</p><pre>List&lt;AggregateResult&gt; aggResults = [SELECT COUNT(Id) oppId, StageName oppStage FROM Opportunity WHERE StageName != &#39;Open&#39; GROUP BY StageName  HAVING COUNT(Id) &gt; 1];<br>for (AggregateResult aggRecord : aggResults) {<br>    <br>    Integer numberOfOppRecords        = (Integer) aggRecord.get(&#39;oppId&#39;);<br>    String opportunityStageName       = (String) aggRecord.get(&#39;oppStage&#39;);<br><br>    System.debug(&#39;The Opp Id :&#39; + numberOfOppRecords);<br>    System.debug(&#39;The Opp stage name :&#39; + opportunityStageName);<br>}</pre><p><em>Limitations:</em></p><p>1. We can’t use logical operation in the queries so, we can use ‘ , ’ separated values in the GROUP BY clause.<br>2. Aggregate queries are not supported in the batch apex.<br>3. Any field that is used in the aggregate function can’t be used in the GROUP BY clause.<br>3. Inner queries in SF will not support Aggregate quires as the results are group of record.</p><pre>No - X : <br>SELECT COUNT(ID) FROM Account WHERE Industry = &#39;Energy&#39; AND Active__c = &#39;true&#39;;<br><br>BATCH APEX will not support agg quires.<br><br>SELECT COUNT(StageName) FROM Opportunity GROUP BY StageName<br><br>SELECT Id, Name FROM Accout WHERE (SELECT COUNT(AccountId) FROM Contact) </pre><p>Lets learn together to know more on this topic as it is bit complex if you are new to SOQL. I would be happy to share more insight details on this topic.</p><p>Connect with me : <a href="https://www.linkedin.com/in/sagar-rpro/">https://www.linkedin.com/in/sagar-rpro/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1400b68abe3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>