<?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 Shubham Sonar on Medium]]></title>
        <description><![CDATA[Stories by Shubham Sonar on Medium]]></description>
        <link>https://medium.com/@coderhamster?source=rss-1edd9afbdd86------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WtYUks00DGUflqbCLreakw.jpeg</url>
            <title>Stories by Shubham Sonar on Medium</title>
            <link>https://medium.com/@coderhamster?source=rss-1edd9afbdd86------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:52:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@coderhamster/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[Implementing Apex BEST Practices should target business efficiency first]]></title>
            <link>https://medium.com/@coderhamster/implementing-apex-best-practices-should-target-business-efficiency-first-f9c3a8978d92?source=rss-1edd9afbdd86------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9c3a8978d92</guid>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[efficiency]]></category>
            <dc:creator><![CDATA[Shubham Sonar]]></dc:creator>
            <pubDate>Sun, 08 Mar 2020 09:54:04 GMT</pubDate>
            <atom:updated>2020-03-08T11:49:55.669Z</atom:updated>
            <content:encoded><![CDATA[<p>Salesforce provides a list of <a href="https://developer.salesforce.com/page/Apex_Code_Best_Practices">Apex Best practices</a> for implementing good customisations. Clearly each best practices has a well-defined purpose behind it. The purpose is what needs to be followed. Following the bullet points in the document can be the fastest way to achieve but can have a big impact to business at times.</p><p>Why? let’s see.</p><p>Apex is server side Language, provided on top of Salesforce Cloud Platform which helps you build customisations. Your Org is running on a Cloud Server on which other Org’s also run in parallel(logical isolation). Cloud Server at day end is a computer with high end computational power. It’s where life become different for Apex, since it needs to handle <a href="https://www.gartner.com/en/information-technology/glossary/multitenancy">multi-tenancy</a> in addition to your code errors.</p><p>During Apex Execution, you have been allotted with some memory(heap) for storing the runtime data. The memory size allotted are as below:</p><blockquote><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">6MB (Synchronous Apex Execution)</a></blockquote><blockquote><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">12MB (Asynchronous Apex Execution)</a></blockquote><p>Definitely, if your Apex Execution Context exceeds these limits, you will see an error as below:</p><blockquote><a href="https://help.salesforce.com/articleView?id=000321537&amp;language=en_US&amp;type=1&amp;mode=1">‘Apex heap size too large’</a></blockquote><p>This limits are to ensure each Org uses its own part of memory on server its running on and the services are highly available to other Org running on same server as well as to avoid any memory outages.</p><p>Similarly, there is one more important governor limit called as ‘<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"><strong>Execution Time</strong></a>’ which is <strong>10 minutes</strong> per transaction. This is to ensure processors on which you are running are highly available by avoiding execution of a long running nasty code.</p><p>This takes us to an important aspect where <strong>Time</strong> and <strong>Space </strong>both needs to be taken care of instead looking at just one of them.</p><p>The Third important aspect is handling large volume of data in your apex, where both of our earlier concerns do co-exists, apart from the third apex expectation which is <strong>Bulkification</strong>.</p><p>One way of avoiding bulkification is making efficient use of Collections (Maps, Lists &amp; Set) to avoid <strong>NESTED QUERIES</strong> in most of the cases. This has created a limits <strong>TRIOLOGY</strong>. How? Let’s see.</p><p>If you are making use of Collections, you tend towards using heap <strong>Memory</strong> and <strong>Time</strong> for sure if you are again iterating on those collections. So how to handle this, should we bulkify really?</p><p>Hence this story, to make you think for at least some minutes with this perspective in mind before implementing or even designing an Apex customisation.</p><p>The answer really depends on the business scenarios, to exactly what box does the Apex required in the story fits in.</p><blockquote>Can this Apex be avoided by any Configurable Solution (like Flows)?</blockquote><blockquote>What other governor limits are/can arrive to our desks?</blockquote><blockquote>Are you sure, the SOQL query inside for loop and for loops iteration is controlled?</blockquote><blockquote>Is this Apex written for User Interface Actions and will not be triggered by data migration activities?</blockquote><blockquote>Should your Apex behave differently as per scenarios (User Actions, Process Automations, etc.)?</blockquote><blockquote>What is the business critical functionality in your Apex that you cannot negotiate with Best practices?</blockquote><blockquote>Will it be easy running an Anonymous Script / Batch &amp; Keeping the Apex toggled OFF as part of data migrations?</blockquote><h3><strong>Three flavours of Apex:</strong></h3><blockquote>Don’t follow Best Practices <strong>(Never Recommended)</strong></blockquote><blockquote>With Best Practices <strong>(Recommended)</strong></blockquote><blockquote>With Some Best Practices and reflects Business Efficiency <strong>(Highly Recommended)</strong></blockquote><p>A good way to experience this will be to implement below <a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_Datacloud_FindDuplicatesResult.htm">example</a> from Salesforce for Lead Object with large Lead Data Migration scenarios &amp; complex duplication merge logic + it should also work on Lead creation component.</p><figure><img alt="getDuplicateResults Apex" src="https://cdn-images-1.medium.com/max/1024/1*Sv2z4zDX7NzI8KIMZ0_Xrw.png" /><figcaption>Code Snippet to find duplicate Account records in your Org.</figcaption></figure><p>If you always hate nested for loops, you need to get a shoulder to cry 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9c3a8978d92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Apex Method Return Values from Javascript perspective]]></title>
            <link>https://medium.com/@coderhamster/understanding-apex-method-return-values-from-javascript-perspective-8ab6c57540e0?source=rss-1edd9afbdd86------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ab6c57540e0</guid>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[lightning-components]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[lightning-web-component]]></category>
            <dc:creator><![CDATA[Shubham Sonar]]></dc:creator>
            <pubDate>Thu, 05 Mar 2020 05:31:37 GMT</pubDate>
            <atom:updated>2022-12-26T12:28:24.561Z</atom:updated>
            <content:encoded><![CDATA[<p>Salesforce provides various programming models to add or implement a customisation to your Salesforce Org. These are:</p><ul><li><strong>Lightning Component</strong> (Aura Framework)</li><li><strong>Lightning Web Components</strong> (Based from ES6 <a href="https://www.webcomponents.org/introduction">Web Components</a>)</li><li><strong>Visualforce</strong> (Article doesn’t targets to this one much since apex method executions are managed by Visualforce page processing done at server side with help of Visualforce tags and attributes which reduce the need of JS based Apex server calls.)</li></ul><p>All of these render as a HTML+JS+CSS page in your browser at day end, be it Salesforce or any other Web App. While building one of these you will notice a way in which you can use Javascript to add some client side logic alongside the Salesforce Server Language - Apex. Apex in itself is a powerful language which takes care of Salesforce cloud governance for you and pretty much the logic related to any automation you want to achieve inside you Salesforce Org (Including Org sessions) and Data can be written out in Apex.</p><p>We tend to use Javascript wherever it is possible to reduce the processing time on Salesforce server side hence reducing the overall throughput time to perform an action in Salesforce. From the perspective of vanilla (Traditional non-flavoured) Javascript, all of above customisations might need to be called from Apex layer (Apex class) to get some data in form of records (SOQL query), flag (boolean against an operation performed in apex), and the list goes on.</p><p>Any Apex method that you are calling from your Javascript, receives the apex method’s return value in javascript(unless apex is returning <strong>null</strong>). The question here is if Apex has different data types to returns as shown below.</p><blockquote>[<strong>P</strong>]<a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_primitives.htm">Primitives Data Types</a></blockquote><blockquote>[<strong>S</strong>]sObjects — For ex. Contact</blockquote><blockquote>[<strong>C</strong>]Combination - Apex defined also called as <em>Wrapper Class</em></blockquote><blockquote><strong>List/Map &lt;P/ S / C / Combination of List/Map&gt;</strong></blockquote><p>How are they mapped to javascript data types? Let’s find out the answers.</p><p>Below image illustrates how <a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_primitives.htm"><strong>Primitive Data Types</strong></a><strong> </strong>in apex are received in Javascript:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NvdNxo8IzBRMHNw6QcNyww.png" /><figcaption>Apex Primitive Data Types checked with <strong>Typeof</strong> in <strong>JS</strong></figcaption></figure><p><strong>sObjects</strong> returned from Apex are received as Javascript Objects (JSON). For example If I write an apex to return a Contact record with FirstName, LastName and InstagramHandle__c, then the JSON received in JS would be something like below:</p><blockquote>{</blockquote><blockquote><strong>FirstName</strong>: “Shubham”,</blockquote><blockquote><strong>LastName</strong>: “Sonar”,</blockquote><blockquote><strong>InstagramHandle__c</strong>: “coderhamster”</blockquote><blockquote>}</blockquote><p>Here the JSON representation is nothing but key value pairs with key as the API name of the fields returned and value as the field value (this field value are received as per the primitive data types discussed above).</p><p><strong>Tip:</strong> If you want to create object in javascript to call an apex method which takes sObject as parameter(for ex. Contact), one way to do it would be as below in your JS:</p><blockquote>//Define an object.</blockquote><blockquote>let contact = {};</blockquote><blockquote>contact.FirstName = ‘Shubham’;</blockquote><blockquote>contact.LastName = ‘Sonar’;</blockquote><blockquote>contact.InstagramHandle__c = ‘coderhamster’;</blockquote><blockquote><strong>//Makes your JS object understandable as a Contact sObject in Apex</strong></blockquote><blockquote><strong>contact.sobjectType = ‘Contact’;</strong></blockquote><p>Let’s see other returns types in Apex.</p><blockquote><strong>LIST</strong> in Apex is represented as <strong>Array</strong> in Javascript. This can be list of primitives, apex wrapperClassObject, Map, List or Combination.</blockquote><blockquote><strong>Apex Wrapper Class </strong>objects and <strong>Map</strong> is represented as <strong>JSON</strong> respecting the primitives, which may be combination of primitives, list, map in Javascript.</blockquote><p>Developer’s visualisation is key aspect of development. Console.logging the data is kungFu Panda way to do it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ab6c57540e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>