<?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 Sriharimavireddy on Medium]]></title>
        <description><![CDATA[Stories by Sriharimavireddy on Medium]]></description>
        <link>https://medium.com/@sriharimavireddy.ms?source=rss-83559675068a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8ciMdxBX74y07rtl</url>
            <title>Stories by Sriharimavireddy on Medium</title>
            <link>https://medium.com/@sriharimavireddy.ms?source=rss-83559675068a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 00:19:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sriharimavireddy.ms/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[Salesforce DevOps Process Using GitHub+ Salesforce Devops Center.]]></title>
            <link>https://medium.com/@sriharimavireddy.ms/salesforce-devops-process-using-github-c508bd69f69d?source=rss-83559675068a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c508bd69f69d</guid>
            <dc:creator><![CDATA[Sriharimavireddy]]></dc:creator>
            <pubDate>Wed, 05 Aug 2026 21:19:54 GMT</pubDate>
            <atom:updated>2026-08-05T21:29:28.292Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Why DevOps Matters in Salesforce</strong></p><p>DevOps is something Salesforce doesn’t give you out of the box. If you’re used to working with Sandboxes, Change Sets, or manual deployments, you already know how messy things get once a team grows past two or three developers. There’s no built-in way to track who changed what, no proper version history, and no clean way to roll back a bad deployment. That’s the gap and it’s a gap most Salesforce teams don’t think about until they get burned by it once.</p><p>This is why teams bring in Git and GitHub to fill that gap and give Salesforce projects the same discipline that regular software teams have had for years: version control, code review, structured branching, and a repeatable release process.</p><p><strong>Where to Start</strong></p><p>Before jumping into GitHub, a few things need to be in place:</p><ol><li><strong>Understand what Git is doing for you</strong> : it’s not just a backup tool, it’s tracking every single change so nothing gets lost or overwritten by mistake.</li><li><strong>Set up your tools: </strong>VS Code, the Salesforce CLI, and a GitHub account/repo connected together.</li><li><strong>Decide on DevOps Center vs plain Git/GitHub</strong> : Salesforce’s own DevOps Center can sit on top of GitHub and gives you a UI for promotions, but the underlying mechanics are still Git.</li><li><strong>Plan your branching strategy first</strong> : this is the part most teams skip and regret later. Decide upfront how release branches, feature branches, and hotfixes will work before anyone starts committing code.</li></ol><p>Once these four are sorted, you’re ready to actually start building the pipeline which is what the rest of this document walks through.</p><p><strong>Part 1: Git &amp; GitHub Basics</strong></p><p><strong>What is Git?</strong></p><p>Git is a version control system used to track changes in source code during development. It’s a piece of software a command line tool that helps a team coordinate their work and keeps track of changes to any set of files, even when multiple people are working on them at the same time.</p><p>Git works across three areas:<br> <strong>Local Working Directory → Staging Area → Local Repository</strong></p><p><strong>What is GitHub?</strong></p><p>GitHub is a cloud-based, web platform where code is stored, shared, and worked on together as a team. It gives you everything Git offers — distributed version control and source code management — plus its own added features like pull requests, code review tools, and project boards.</p><p>Think of GitHub as your <strong>Remote Repository</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*ZfSNzs6b6cBmOlzb1HXFZg.png" /></figure><p><strong>Key Concepts</strong></p><p><strong>Remote Repository</strong><br> A repository that’s hosted externally, on a service like GitHub or GitLab, instead of sitting only on someone’s laptop.</p><p><strong>Local Repository</strong><br> This is the copy of the repository stored on your own machine. You use this local copy to make changes and test them before pushing anything to the main/central repository.</p><p><strong>Staging Area</strong><br> This is basically a waiting area — a place where changes sit after you’ve selected them, but before they’re actually committed to the local repository. It acts as a buffer between your working directory and your repository.</p><p><strong>Working Directory</strong><br> This is simply where you’re actively writing and editing code — like your VS Code window.</p><p><strong>Core Git Commands ::</strong></p><p><strong>git init</strong><br> This turns any folder into a Git repository. It creates a hidden .git folder and that hidden folder is what actually makes a regular directory into a Git-tracked one.</p><p>Use this when your project already exists locally but hasn’t been connected to Git yet.</p><ul><li>git init — turns the current directory into a Git repo</li><li>git init &lt;directory&gt; — turns a specific folder into a Git repo</li></ul><p><strong>git clone</strong><br> Used to create a copy of an existing repository (or a specific branch inside it) onto your local machine.</p><p><strong>git status</strong><br> Shows you the current state of your working directory and staging area. Specifically, it tells you:</p><ul><li>Which files have changed</li><li>Which changes are staged and which aren’t</li><li>Which files Git isn’t tracking at all</li><li>Whether your local branch is ahead or behind the remote branch</li><li>What your current changes are pointing to — a branch or a specific commit</li></ul><p><strong>git add</strong><br> Moves new or changed files from your working directory into the staging area.</p><p>This is especially useful when you or your team are working on multiple things at once, and you only want to commit one specific piece.</p><ul><li>git add [filename] — stages one specific file</li><li>git add [path] — stages an entire folder/directory</li><li>git add -A — stages all modified or deleted files (but not newly created ones)</li><li>git add -p — lets you go chunk-by-chunk through changes and choose what to stage (yes/no/skip)</li></ul><p><strong>git commit</strong><br> Takes whatever is in the staging area and saves it as a snapshot in your local repository.</p><p>Every commit works like a checkpoint a point in time you can always come back to.</p><p>git commit -m &quot;updated class file&quot;</p><p>Commits are always made to whichever branch you’re currently checked into (wherever HEAD is pointing). That’s why it’s good practice to run git status before committing just to double check you&#39;re on the branch you actually meant to be on.</p><p><strong>How to Undo Things in Git</strong></p><p><strong>git revert</strong><br> The safest way to undo something without rewriting history. Instead of deleting a commit, it looks at what changed in that commit and creates a brand new commit that applies the opposite of those changes. So it works like an “undo,” but keeps your repository’s history intact.</p><p><strong>git reset</strong><br> Used when you need to actually remove a commit — for example, if it contains sensitive information that shouldn’t stay in the history at all.</p><p><strong>git reflog</strong><br> A log of everywhere HEAD has pointed to. This is your safety net — if you use git reset and accidentally lose commits, git reflog lets you find and recover them.</p><p><strong>git commit — amend</strong><br> Replaces your most recent commit with a new one useful for small fixes right after committing (like a typo in the commit message or a missed file).</p><p><strong>Connecting to a Remote Repository</strong></p><p>git remote add origin &lt;url of the repo&gt;</p><p>This links your local repository to a remote one (like GitHub). Once that connection exists, the remote will usually have a main/master branch from there, you clone or branch off it, do your work, and create a pull request to merge back in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*To7eEQZN340RKJaVLyRgbw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*QOZVx5Y-eKAUcZsDC4393g.png" /></figure><p><strong>What is DevOps Center?</strong></p><p>DevOps Center is Salesforce’s own tool that sits on top of GitHub and gives your team a proper structured way to move changes from one environment to another without relying only on manual deployments or Change Sets.</p><p>Instead of just pushing metadata around, DevOps Center connects directly to your GitHub repository behind the scenes. Every time you pull changes from an org, it creates the branch, tracks the commit, and manages the pull request for you all through a UI, so your team doesn’t need to know every Git command to still follow proper version control practices.</p><p>In short: Git and GitHub are doing the real work underneath, but DevOps Center gives you a visual pipeline Dev → QA → UAT → Production where you can see exactly what’s in each stage, promote changes forward, and roll them back if something breaks.</p><p>This is especially useful for Salesforce teams because unlike regular code, Salesforce metadata is harder to track manually DevOps Center bridges that gap by pairing Salesforce’s org-based development model with GitHub’s version control strength.</p><p><strong>Setting Up DevOps Center Step by Step:</strong></p><ol><li>Download VS Code and authorize it against your Salesforce production org this pulls the code down and creates a project folder locally.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*0R1Hj2StDDrhn09w2_436g.png" /></figure><p>2. Create an empty repository on GitHub (this becomes your remote repository).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*mOJ6MvwoaCk6s6r4hLhmiA.png" /></figure><p>3. Link VS Code to that GitHub repository.</p><p>Initialize an empty Git repository locally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*P4VJhi1VYJfBHiGcDWBaig.png" /></figure><p>4. Create your first commit with all the files retrieved from Salesforce.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*xJ6mFUGsxCjvSlCpMuNR5A.png" /></figure><p>5. Link everything to the remote repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*Jj4lnrkIyVnyC_fM7un38A.png" /></figure><p>6. Create or rename your branch, and push your first commit from local to remote.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*qqnyUm20oBooBE8MqH1A9A.png" /></figure><p>7. Confirm the push landed correctly on the master branch remotely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*4kui8KGVPpLLxmZ52oL5iA.png" /></figure><p>8. Go into DevOps Center in Salesforce and create a new project using the existing repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*WbNbki7zdBGKmoDModRABQ.png" /></figure><p>9. Set up a pipeline with staging and production environments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*XMFR-rA5NnGuaE-Hi3QBwg.png" /></figure><p>10. Sync your dev org with the next stage in the pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*M-mrxbMO_1j6sq5vtQiEUw.png" /></figure><p>11. Create a work item inside DevOps Center.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*nHh6OiPRu8fURFwJQ_d9AA.png" /></figure><p>13. Make your development changes in the dev org, then deploy those changes from VS Code into the org.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*-Z1oMpu15ccsb7_4h11nng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*UTnk4wuU_ssixA6eCMHLYQ.png" /></figure><p>14. Back in the work item, select the dev org with your changes, click <strong>Pull</strong>, select the changes, and click <strong>Commit</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*UL_E4d8JicW-WStgiTSboQ.png" /></figure><p>15. A feature branch is automatically created in GitHub at this point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Xd3liJcNfkOlsjwT31lJ_w.png" /></figure><p>16. Review and merge the pull request once approved, it gets merged and closed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*PgVNKJQWsxYiGNa8uUzXTw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*PaZe0VPNRhZKEnC5n2N5oA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*reO7e5WEY6ZVj3v-obAKPQ.png" /></figure><p>17. Your changes are now staged. Select the relevant stories and click <strong>Promote</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*e_IESWxuqO5c8sHqCyj9-A.png" /></figure><p>18. This promotes changes from QA to UAT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*HfgYbll2xOQ_4cqz0xF0iA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*U2JaLhPnq83QF_mL6HeIHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*5TnT0J274hijXgUM9F9m5w.png" /></figure><p>19. If issues come up in UAT, you have the option to revert the code back.</p><p>Overall branching view using gitgraph extension:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*ossMsot3ZFd6CwkX4mnx5Q.png" /></figure><p>More about branching models — <a href="https://nvie.com/posts/a-successful-git-branching-model/">https://nvie.com/posts/a-successful-git-branching-model/</a></p><p><strong>Drawbacks and Limitations of DevOps Center</strong></p><p>DevOps Center is a big step up from Change Sets, but it’s still not a mature tool it has real gaps that can slow your team down if you’re not aware of them going in.</p><p>Here are few errors Iencountered while learning/implementing this tool.</p><p><strong>1. Limited source control support</strong><br> DevOps Center only works with GitHub.com and Bitbucket Cloud (Bitbucket is still in beta). It doesn’t support GitHub Enterprise Server, GitLab, Azure DevOps, or other version control systems. If your company already uses one of those, you’re stuck either switching your whole setup to GitHub or not using DevOps Center at all.</p><p><strong>2. No CI/CD or automated rollback</strong><br> One of the biggest gaps in DevOps Center is that it has no built-in DevOps automation for setting up and managing a proper CI/CD pipeline. There’s also no built-in rollback and no native Jira integration teams usually end up bolting on separate tools to cover these gaps.</p><p><strong>3. Frequent errors during heavy use</strong><br> Teams running multiple parallel implementations report hitting the “Too many callouts: 101” error repeatedly, especially when the org has a lot of simultaneous activity it overwhelms the pipeline and disrupts the workflow. Also common: merges failing during promotion, forcing teams to merge feature branches manually outside DevOps Center and those manual merges don’t sync back into the pipeline right away, which causes delays.</p><p><strong>4. UI/Kanban board glitches</strong><br> The interface looks like a simple Kanban board, but the “Ready to Promote” status can randomly disappear from the screen, forcing developers to create brand new work items just to retry wasted time for something that should just work.</p><p>Here is the github link by devops center team about these known issues — <a href="https://github.com/forcedotcom/devops-center-feedback/blob/main/KNOWNISSUES.md">https://github.com/forcedotcom/devops-center-feedback/blob/main/KNOWNISSUES.md</a></p><p><strong>Closing Note:</strong></p><p>DevOps Center is a genuine step forward for Salesforce teams it brings version control, structured branching, and a visual pipeline to a process that used to run entirely on Change Sets and guesswork. But as covered above, it’s still an early-stage tool. Frequent errors, no real CI/CD, no rollback support, and limited version control options mean teams need workarounds to keep things running smoothly, especially as projects grow in size and complexity.</p><p>The good news is that most of these gaps aren’t dead ends they’re exactly the kind of problems GitHub Actions was built to solve.</p><p><strong>Coming up next</strong>, we’ll look at how to bring GitHub Actions into this workflow setting up automated pipeline validation, build checks, and deployment automation to close the gaps DevOps Center leaves open. This is where the process moves from “manually promoting and hoping” to a proper automated release pipeline, matching what’s shown in the flowchart we started with pipeline validation triggers, automated checks before code review, and a repeatable, reliable path from feature branch to production.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c508bd69f69d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Salesforce Integration (REST API)]]></title>
            <link>https://medium.com/@sriharimavireddy.ms/salesforce-integration-rest-api-d49dcf19d843?source=rss-83559675068a------2</link>
            <guid isPermaLink="false">https://medium.com/p/d49dcf19d843</guid>
            <dc:creator><![CDATA[Sriharimavireddy]]></dc:creator>
            <pubDate>Sun, 05 Apr 2026 23:53:12 GMT</pubDate>
            <atom:updated>2026-04-05T23:53:12.345Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is Integration?</strong></p><p>Integration is a process of connecting two or more systems to communicate for data transfer or for a process to be done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*JuLnNy9A6zIGNqXBI7DXqw.jpeg" /></figure><p><strong>Why does Salesforce need Integration?</strong></p><p>Salesforce can’t be the source of everything. It can be CRM or any Custom application. The possibility that Salesforce would need to exchange data with systems like a payment system or any external systems is high.</p><p><strong>Rule 1: </strong>The API (Application Programming Interface) must be at the receiving system; in other words, the API has to be made available, providing the services.</p><p><strong>Different Types of Integrations:</strong></p><ol><li>Outbound Integration: When you want to get data from an external system, we will initiate the request. (Calling external system using Apex). Or ( Any External system reaching Salesforce to request data).</li><li>Inbound Integration: When an external system sends data from an external system, the External system initiates the request. (SAP system sending data ). Or ( Salesforce requesting other external systems to request data)</li></ol><h3>REST vs SOAP API:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*hudQwQg38VHZ5-G9_xGvYw.jpeg" /></figure><h3>JSON vs XML:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dcctPFKdB3KzxNKZ.png" /></figure><p><strong>Things Required for Callout:</strong></p><p>Remote Site Setting: Create a new remote site with the URL that you are trying to communicate with. ( <a href="https://reqres.in/">https://reqres.in/</a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKeav_eL8oFx5KmstYRQyQ.png" /></figure><p><strong>Authorization:</strong> An API key that we get from an external system.</p><p><strong>Scenario 1: Salesforce to External System Using Apex Rest Callout.</strong></p><pre>request.Header(&#39;Authorization&#39;,&#39;API KEY&#39;);<br>request.setHeader(&#39;Authorization&#39;, &#39;Bearer reqres-free-v1&#39;);<br>//Bearer is a token-based authentication used in HTTP headers to authenticate API requests. <br>//It tells the server that the client is using a token to prove its identity.</pre><p><strong>API details:</strong> Details like URL, Operation type, and inputs to get data.</p><pre>        Http httpobj= new Http();<br>        //This is the Reference  method used to send a request to the external<br><br>        HttpRequest req = new HttpRequest();<br>        //Request Object<br><br>        req.setEndPoint(&#39;https://reqres.in/api/users?page=2&#39;);<br>        //request.setEndpoint(&#39;URL&#39;);<br>        <br>        req.setHeader(&#39;Content-Type&#39;,&#39; application/json&#39;);<br>        //req.setHeader(&#39;key&#39;, &#39;value&#39;);<br><br>        request.setHeader(&#39;Authorization&#39;, &#39;Bearer reqres-free-v1&#39;);<br>        //Authorization is required if the site is private.<br><br>        req.setMethod(&#39;GET&#39;);<br>        //req.setBody(body);<br><br>        HttpResponse res = new HttpResponse();<br>        //Response Object<br><br>        res = httpobj.send(req);<br>        System.debug(&#39;Response &#39; + res.getBody());</pre><p><strong>What is the difference between Http , HttpRequest and HttpResponse.</strong></p><p><strong>Http </strong>— Acts as Executor , which will actually open the Network Connection.</p><p>Methods Available — Send();</p><p><strong>HttpRequest </strong>— It defines the request with all the details of the request.</p><p>Methods Available — setEndPoint() , setMethod();</p><p><strong>HttpResponse </strong>— It holds the Response from External system.</p><p>Methods Available — getBody() , getStatusCode();</p><h3><strong>Standard Rest API VS Composite Rest API</strong></h3><p><strong>Standard Rest API :</strong></p><p>These are pre built, out of the box interfaces that allow external applications to interact with salesforce and metadata without requiring custom apex code.</p><p>In simple words, For any insert/update/delete/query operations on any salesforce object ,salesforce offers APIs called Standard APIs.</p><pre>Http http = new Http();<br><br>HttpRequest req = new HttpRequest();<br>//SetendPoint contains details about object it is performing operation<br>req.setEndpoint(&#39;https://yourInstance.salesforce.com/services/data/v60.0/sobjects/Account&#39;);<br>req.setMethod(&#39;GET&#39;);<br>req.setHeader(&#39;Authorization&#39;, &#39;Bearer YOUR_ACCESS_TOKEN&#39;);<br><br>HttpResponse res = http.send(req);<br><br>System.debug(&#39;Status Code: &#39; + res.getStatusCode());<br>System.debug(&#39;Response Body: &#39; + res.getBody());</pre><p><strong>Composite Rest API :</strong></p><p>REST based service that allows you to execute multiple operations in a single call. Including the ability to chain requests by using the output of one request as input to another.</p><pre>Http http = new Http();<br><br>HttpRequest req = new HttpRequest();<br>req.setEndpoint(&#39;https://yourInstance.salesforce.com/services/data/v60.0/composite&#39;);<br>req.setMethod(&#39;POST&#39;);<br>req.setHeader(&#39;Authorization&#39;, &#39;Bearer YOUR_ACCESS_TOKEN&#39;);<br>req.setHeader(&#39;Content-Type&#39;, &#39;application/json&#39;);<br>//This request body contains POST request to different objects in single callout Account and contact.<br>req.setBody(&#39;{&#39; <br>&#39;&quot;compositeRequest&quot;: [&#39; <br>    &#39;{&#39; <br>        &#39;&quot;method&quot;: &quot;POST&quot;,&#39; <br>        &#39;&quot;url&quot;: &quot;/services/data/v60.0/sobjects/Account&quot;,&#39; <br>        &#39;&quot;referenceId&quot;: &quot;ref1&quot;,&#39; <br>        &#39;&quot;body&quot;: {&quot;Name&quot;: &quot;Test Account&quot;}&#39; <br>    &#39;},&#39; <br>    &#39;{&#39; <br>        &#39;&quot;method&quot;: &quot;POST&quot;,&#39; <br>        &#39;&quot;url&quot;: &quot;/services/data/v60.0/sobjects/Contact&quot;,&#39; <br>        &#39;&quot;referenceId&quot;: &quot;ref2&quot;,&#39; <br>        &#39;&quot;body&quot;: {&#39; <br>            &#39;&quot;LastName&quot;: &quot;John&quot;,&#39; <br>            &#39;&quot;AccountId&quot;: &quot;@{ref1.id}&quot;&#39; <br>        &#39;}&#39; <br>    &#39;}&#39; <br>&#39;]&#39; <br>&#39;}&#39;);<br><br>HttpResponse res = http.send(req);<br><br>System.debug(res.getBody());</pre><p><strong>NOTE</strong>: Standard REST APIs url defines which object is gonna CREATE/UPDATE/INSERT/QUERY. We cannot change its behavior by sending conditions as parameters.</p><p><strong>APEX REST API :</strong></p><p>Fully custom REST callouts using Apex.</p><pre>@RestResource(Urlmapping = &#39;/AccountContactApi&#39;)<br>global class AccountContactApi{<br><br>    @httpPost<br>    global static void createdFrmExternalSystem(){<br>          RestRequest req = RestContext.Request;<br>          RestResponse res = RestContext.Response;<br>          //Request body that we received from external system should be converted into string formate.<br>          String body = req.requestBody.toString(); // {&quot;CustomerName: &quot;Sri Hari&quot; , isAccount&quot; :true)<br>          //Split that json into sepreate parts using helper class and typecaste it with class.<br>          MyJsonClass myObj = (MyJsonClass) JSON.deserialize( body , MyJsonClass.Class);<br>       <br>          System.debug(&#39;@@@&#39; + myObj.CustomerName+ &#39;@&#39; + myObj.isAccount);<br> <br>          if(myObj.isAccount==true){<br>              Account acc = new Account(Name= myObj.CustomerName);<br>              INSERT acc;<br>          }<br>          else if(myObj.isAccount==false){<br>               Contact con = new Contact(LastName = myObj.CustomerName);<br>               INSERT con;<br>           }<br>   }<br></pre><pre>//Helper class used to assign datatypes to variables<br>public class myJsonClass{<br>     public String CustomerName;<br>     public Boolean isAccount;<br>}</pre><p>This Rest callout should create Account if isAccount field is true Else if isAccount is False it will create Contact.(This is decided based on the request body from external system.</p><p><strong>When to use Apex Rest API:</strong></p><ol><li>If its not possible with Standard Rest API, then blindly choose Apex Rest API.</li></ol><p>2. Apex Rest API supports complex logic/calculations to be done before Insert/Update/Query/Delete.</p><p>3. External System sends Request body which is not supported format of standard Rest API (Like customerName is sent Instead of Name to created account).</p><p><strong>Conclusion:</strong></p><p>Choosing the right API depends on the complexity of the requirement. Standard APIs are best for simple CRUD operations, Composite APIs help reduce API calls, and Apex REST APIs provide flexibility for complex business logic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d49dcf19d843" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Salesforce Portfolio That Speaks Louder Than Your Resume]]></title>
            <link>https://medium.com/@sriharimavireddy.ms/building-a-salesforce-portfolio-that-speaks-louder-than-your-resume-1d30dbaef151?source=rss-83559675068a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d30dbaef151</guid>
            <dc:creator><![CDATA[Sriharimavireddy]]></dc:creator>
            <pubDate>Tue, 11 Feb 2025 23:28:19 GMT</pubDate>
            <atom:updated>2025-05-13T18:29:33.967Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>A short brief about me:</strong></p><p>I am <strong>Sri Hari Mavireddy</strong>, with 5<strong>+ years of hands-on experience</strong> as a <strong>Salesforce Administrator , Developer and Quality Assurance Engineer</strong>. A year ago, I left my job to pursue my <strong>Master’s degree</strong> and started learning new things about Salesforce every day.</p><p>One day, while creating my resume, I had the idea to showcase my knowledge creatively by building a <strong>portfolio</strong> for hiring teams. I implemented key functionalities such as <strong>WhatsApp integration</strong> and <strong>automated email notifications</strong> to connect with recruiters interested in learning more about me and considering me for their team.</p><p>Here is the link to my portfolio that I am talking about:</p><p><strong>Portfolio </strong>— <a href="https://sriharimavireddyportfolio-dev-ed.develop.my.site.com/PortfolioLWCUI/">https://sriharimavireddyportfolio-dev-ed.develop.my.site.com/PortfolioLWCUI/</a></p><p><strong>Linkedin</strong> — <a href="https://www.linkedin.com/in/sri-hari-mavireddy-a5099217a/">https://www.linkedin.com/in/sri-hari-mavireddy-a5099217a/</a></p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -</p><p><strong>Prerequisites:</strong></p><ul><li>Salesforce Developer Edition org.</li><li>VS code connection with developer org.</li><li>Salesforce CLI installed.</li></ul><p><strong>Step-1 :</strong></p><p>Create a new Digital Experience site using a template — Build your own LWR template.</p><p><strong>Step -2 :</strong></p><p>Create different lightning Web Components based on different sections that you want to add to your website.</p><p>For my resume, I created the below sections:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*besGTlFlhFvs8FHp_diuRw.png" /></figure><ul><li><strong>MyPortfolio</strong> Components refers to The header of my portfolio which acts as the main navigation menu. It displays all section names, and when you click on any name, it smoothly scrolls to that specific section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bwZlxJhWM_8PH9jIxl3-Yg.png" /></figure><ul><li><strong>myPortfolioHome</strong> Component contains the Name, display picture, and links to redirect to GitHub and LinkedIn.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tUx4ENHwTpBepgXRXXV2Yg.png" /></figure><ul><li><strong>portfolioEducationSection</strong> Component contains education details with the university logo.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*67mPoePr55ShWVg22GHrKw.png" /></figure><ul><li><strong>portfolioExperienceSection </strong>Component contains past work experiences in different organizations.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CGy5WqBJPJMGrgvXEXdKCA.png" /></figure><ul><li><strong>PortfolioSkillSection</strong> Component contains my overall skillset and different professional certifications that i hold.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lzGIvvq-8DGxWaH-rwEFiw.png" /></figure><ul><li><strong>portfolioProjectSection </strong>Component contains different personal projects implemented.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oG_s4dIl6wRxW5zA1_Purg.png" /></figure><ul><li><strong>portfolioContactSection </strong>Component consists of a form to fill in details of people interested in learning more about you.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e5usArTJ-Ou30zBmumXkSw.png" /></figure><p><strong>Step-3:</strong></p><p>Okey……!! Now let’s dive deep into each component’s code.</p><ul><li><strong>MyPortfolio</strong> <strong>Component:</strong></li></ul><p>This component functionality is to navigate to a particular section when you click on that section name. And view varies based on screen size, If the screen is width less than 600 px then use the below logic. If not the hamburger menu will be hidden and only links are available.</p><pre>/* The &quot;responsive&quot; class is added to the topnav with JavaScript when <br>the user clicks on the icon. This class makes the topnav look good on <br>small screens (display the links vertically instead of horizontally) */<br>  @media screen and (max-width: 600px) {<br>    .topnav.responsive {position: relative;}<br>    .topnav.responsive a.icon {<br>      position: absolute;<br>      right: 0;<br>      top: 0;<br>    }<br>    .topnav.responsive a {<br>      float: none;<br>      display: block;<br>      text-align: left;<br>    }<br>  }</pre><p>Initially, I am hiding hamburger icon if the screen size is less than 600px.</p><pre>.topnav .icon {<br>  display: none;<br>}</pre><p>RenderCallBack() life cycle hook in lwc re-runs multiple times after the component is inserted in DOM. When the screen size is changed to &lt;600 px, the icon is displayed. HandleHamburgerClick() finds the elements inside the HTML file and displays the list using the class ‘responsive’ condition.</p><pre>renderedCallback(){<br>    loadStyle(this, Hamicon +&#39;/style.css&#39;);<br>}<br><br>handleHamburgerClick(){<br>   const navMenu = this.template.querySelector(&#39;.topnav&#39;);<br>   console.log(&#39;navMenu&#39;,navMenu);<br>   // responsive is the class name in the css file<br>    navMenu.classList.toggle(&#39;responsive&#39;);<br>  }<br>}</pre><p>Mobile view :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*FtyRhq5skftHrclYvG66ZQ.png" /></figure><p>Desktop or Tablet view :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bwZlxJhWM_8PH9jIxl3-Yg.png" /></figure><ul><li><strong>MyPortfolioHome/portfolioEducationSection/portfolioProjectSection :</strong></li></ul><p>This Component functionality is to shown in two different parts , where one part consists of name and some links to Linkedin and GitHub. And the other part consists of display picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*4qrGUF26W_k6iuU7nF9F9Q.png" /></figure><p>This can be implemented using <strong>slds-medium-size_1-of-2 , </strong>if the screen size is aleast medium split grid into 1 of 2.</p><pre>&lt;div class=&quot;slds-col slds-medium-size_1-of-2 slds-p-around_small&quot;&gt;</pre><p>What if the screensize is of mobilescreen?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*B8MEnmHUvvTz4-ppbV0QXQ.png" /></figure><p>So, to implement this functionality, we need a condition to show the first part 100% and the next part should be moved down.We can implement this using. if screensize is less than medium use <strong>slds-size_1-of-1</strong> and if size is ≥ medium <strong>slds-medium-size_1-of-2.</strong></p><pre>&lt;div class=&quot;slds-col slds-size_1-of-1 slds-medium-size_1-of-2 slds-p-around_small&quot;&gt;</pre><ul><li><strong>PortfolioSkillSection </strong>This section is the eaiest where you can just add text and add some stylings to it.</li><li><strong>portfolioContactSection</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hMHNQVQtR74jk7wo1AOeNg.png" /></figure><p>This can be the main part of this portfolio project.Here is the flow how it works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*dse3M9sbLZpFb04lR5vRAQ.png" /></figure><p><strong>Action — 0 :</strong></p><p>Create a contact in Salesforce by fetching details from ui component. Here, I am getting all the from the from and assigning to contact record values and trying to insert. After account creation just show THANK YOU message.</p><pre> @AuraEnabled<br>    public static String createContact(String lastName, String email, String description, String PhoneNumber) {<br>        try {<br>            // Input validation<br>            if (String.isBlank(lastName) || String.isBlank(email) || String.isBlank(PhoneNumber)) {<br>                throw new AuraHandledException(&#39;Required fields are missing&#39;);<br>            }<br><br>            Contact newContact = new Contact();<br>            newContact.LastName = lastName;<br>            newContact.Phone = PhoneNumber;<br>            newContact.Email = email;<br>            newContact.Description = description;<br>            insert newContact;<br><br>            // Send emails<br>            sendEmail(email, lastName, description);<br>            sendEmailToRecipient(email, lastName);<br><br>            return &#39;Success&#39;;<br>        } catch (Exception e) {<br>            System.debug(&#39;Error creating contact: &#39; + e.getMessage());<br>            throw new AuraHandledException(&#39;Failed to create contact: &#39; + e.getMessage());<br>        }<br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m4uC9PTsC5Xk_PVG7_Cu2Q.png" /></figure><p><strong>Action -1 :</strong></p><p>Send Email to the user and owner with some details when contact is created.</p><pre> @AuraEnabled<br>    public static void sendEmail(String toAddress, String subject, String body) {<br>        try {<br>            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();<br>            mail.setToAddresses(new List&lt;String&gt;{ &#39;satyasriharim.edu2023@gmail.com&#39; });<br>            mail.setSubject(subject + &#39; &#39; + toAddress);<br>            mail.setHtmlBody(body);<br>            Messaging.sendEmail(new List&lt;Messaging.Email&gt; { mail });   <br>        } catch (Exception e) {<br>            System.debug(&#39;Error sending email: &#39; + e.getMessage());<br>            throw new AuraHandledException(&#39;Failed to send email: &#39; + e.getMessage());<br>        }<br>    }<br><br>    @AuraEnabled<br>    public static void sendEmailToRecipient(String toAddress, String lastName) {<br>        try {<br>            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();<br>            mail.setToAddresses(new List&lt;String&gt;{ toAddress });<br>            mail.setSubject(&#39;Thank You for Contacting Me&#39;);<br>            <br>            String body = &#39;Dear &#39; + lastName + &#39;,\n\n&#39;;<br>            body += &#39;Thank you for reaching out to me through my portfolio. I\&#39;m grateful for your interest and excited about the possibility of working together. Let\&#39;s discuss further details at your convenience.\n\n&#39;;<br>            body += &#39;Best regards,\n\n&#39;;<br>            body += &#39;Sri Hari Mavireddy\n\n&#39;;<br>            body += &#39;satyasriharim.edu2023@gmail.com&#39;;<br>            <br>            mail.setPlainTextBody(body);<br>            Messaging.sendEmail(new List&lt;Messaging.Email&gt; { mail });  <br>        } catch (Exception e) {<br>            System.debug(&#39;Error sending recipient email: &#39; + e.getMessage());<br>            throw new AuraHandledException(&#39;Failed to send confirmation email: &#39; + e.getMessage());<br>        }<br>    }<br>}</pre><p>Form user :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fds-A4mG1H0vkpUWKylsww.png" /></figure><p>Form owner:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ID9WfhkP15lcyjucG0J0A.png" /></figure><p>Action-2:</p><p>Send Thank you message(template) to contact phone number whatsapp.This runs as after trigger when contact is created in salesforce.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E2GX5sncM_g-zBN6SmJ1Dw.png" /></figure><pre>public class whatsappIntergrationCont {<br><br>    @future(callout=true)<br>    public static void sendTemplateMessages(List&lt;String&gt; contactIds) {<br>        try {<br>            // Query contact details<br>            List&lt;Contact&gt; contacts = [SELECT Id, Phone FROM Contact WHERE Id IN :contactIds];<br>            Http http = new Http();<br><br>            for (Contact contactDetail : contacts) {<br>                if (contactDetail.Phone != null) {<br>                    // Formating the phone number for WhatsApp (country code + phone number)<br>                    String whatsAppNumber = &#39;1&#39; + contactDetail.Phone;<br><br>                    // Create HTTP request<br>                    HttpRequest req = new HttpRequest();<br>                    req.setEndpoint(&#39;xxxxxxxxxxxxxxxxxx&#39;);<br>                    req.setHeader(&#39;Content-Type&#39;, &#39;application/json&#39;);<br>                    req.setMethod(&#39;POST&#39;);<br><br>                    // Request body for sending a template message<br>                    String body = &#39;{&quot;messaging_product&quot;:&quot;whatsapp&quot;, &quot;to&quot;:&quot;&#39; + whatsAppNumber + &#39;&quot;, &quot;type&quot;:&quot;template&quot;, &quot;template&quot;:{&quot;name&quot;:&quot;hello_world&quot;,&quot;language&quot;:{&quot;code&quot;:&quot;en_US&quot;}}}&#39;;<br>                    req.setBody(body);<br><br>                    // Add Authorization header with the API token<br>                    String apiToken = &#39;xxxxxxxxxxxxxxxxxxxxxxxxx&#39;;<br>                    req.setHeader(&#39;Authorization&#39;, &#39;Bearer &#39; + apiToken);<br><br>                    // Send the HTTP request<br>                    HttpResponse res = http.send(req);<br><br>                    // Debug the response<br>                    if (res.getStatusCode() == 200) {<br>                        System.debug(&#39;Message sent successfully to &#39; + whatsAppNumber);<br>                        System.debug(&#39;Response Body: &#39; + res.getBody());<br>                    } else {<br>                        System.debug(&#39;Failed to send message. Status Code: &#39; + res.getStatusCode());<br>                        System.debug(&#39;Response: &#39; + res.getBody());<br>                    }<br>                } else {<br>                    System.debug(&#39;Contact &#39; + contactDetail.Id + &#39; does not have a phone number.&#39;);<br>                }<br>            }<br>        } catch (Exception e) {<br>            System.debug(&#39;Error during WhatsApp message callout: &#39; + e.getMessage());<br>        }<br>    }<br>}</pre><p>Here is the end of my portfolio!!</p><p>“Thank You for Exploring My Portfolio!</p><p>As a passionate Salesforce professional, I believe in continuous growth and learning. This portfolio is a living document of my journey — constantly evolving as I expand my skills and tackle new challenges.</p><p>I welcome your insights and feedback. Whether you’ve noticed areas for improvement or would like to discuss potential opportunities, I’m always eager to connect and learn from fellow professionals.</p><p>Let’s connect and explore how we can create innovative solutions together in the Salesforce ecosystem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d30dbaef151" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Too Many SOQL Queries:101]]></title>
            <link>https://medium.com/@sriharimavireddy.ms/too-many-soql-queries-101-85974f9ef408?source=rss-83559675068a------2</link>
            <guid isPermaLink="false">https://medium.com/p/85974f9ef408</guid>
            <category><![CDATA[salesforce-usa]]></category>
            <category><![CDATA[salesforce-job]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[salesforce-apex]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <dc:creator><![CDATA[Sriharimavireddy]]></dc:creator>
            <pubDate>Wed, 05 Feb 2025 21:35:06 GMT</pubDate>
            <atom:updated>2025-02-05T21:44:41.192Z</atom:updated>
            <content:encoded><![CDATA[<p>This error occurs when a piece of Apex code executes more than 100 SOQL queries in a single transaction.</p><pre>System.LimitException: Too Many SOQL Queries:101</pre><p>Salesforce has a specific limit of queries that can be executed in a single transaction to ensure efficient use of resources.</p><p><strong>Reproducing errors in different Scenarios:</strong></p><p>Here, I am trying to create 200 Accounts and their related contacts for each.</p><pre>public class AccountConCreation {<br>    <br>    Public static void AccountCon(){<br>        List&lt;Account&gt; accounts = new List&lt;Account&gt;();<br>             for(Integer i=0; i&lt;200;i++){<br>                   accounts.add(new Account(Name = &#39;Test Account &#39; + i));<br>             }<br>             insert accounts;<br>        <br>       <br>        List&lt;Contact&gt; contacts = new List&lt;Contact&gt;();<br>              for(Account acc: accounts){<br>                    contacts.add(new Contact(LastName =&#39;Test Contact &#39;+acc.Name,AccountId = acc.Id));<br>              }<br>              insert contacts;<br>    }<br>}</pre><p><strong>Scenario -1: Avoid SOQL queries inside For Loop.</strong></p><p>Get the Account Name and number of Contacts assigned to that Account.</p><pre>public class AccountConSize {<br>    <br>    Public static void AccountContactSize(){<br>        List&lt;Account&gt; accList= [SELECT id, Name FROM ACCOUNT];<br>        <br>        for(Account acc : accList){<br>            List&lt;contact&gt; contacts = [SELECT id,Name FROM CONTACT WHERE AccountId = :acc.Id];<br>            <br>            System.debug(&#39;Account &#39; +acc.Name + &#39;has &#39; + contacts.size());<br>        }<br>    }<br><br>}</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sXvOHiAO2CJ0jcJSTp9BSg.png" /></figure><p>Debugging:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yw-iLk7zhC1XYiGSejMYAQ.png" /></figure><p>Raw logs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4UZb35HsB0Ofp2VnFQZWPA.png" /></figure><p>Imported Rawlogs to VS Code to analyze better :</p><p>How many SOQL queries were executed?</p><p>(Use CTRL + SHIFT + L to auto-select all the similar lines)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fOxY-tQsrdLZCKNyG0L8NA.png" /></figure><p>— — EXECUTED 1 time.</p><p>16:47:59.0 (2906711)|SOQL_EXECUTE_BEGIN|[4]|Aggregations:0|SELECT id, Name FROM ACCOUNT</p><p>— — EXECUTED 101 Times.</p><p>16:47:59.0 (197401755)|SOQL_EXECUTE_BEGIN|[7]|Aggregations:0|SELECT id, Name FROM CONTACT WHERE AccountId = :tmpVar1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ro2K_tZ5ABvMuT5o7K11vw.png" /></figure><p>Why the same query executed 101 times?</p><p>16:47:59.0 (2391043)|METHOD_ENTRY|[1]|01pHu00000Nc2tP|AccountConSize.AccountConSize()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VvWfehid_-Ibdf1Op-By1w.png" /></figure><p>The root cause can be using SOQL query within the for loop.</p><p>Let’s try avoiding SOQL queries within the for-loop. Built query using parent-child relationship.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6K2T77ZOMdHRMucZOWxf1w.png" /></figure><p>Based on this query, the SOQL query was removed from the for loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LrUhmY76T2I-fgvY7GTdlg.png" /></figure><p>Now our class executed successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3x9krNrfPT0zzYeAZVgHFw.png" /></figure><p><strong>Scenario — 2: Bulkify Trigger.</strong></p><p>This trigger will take the Contact’s lastname as the account name. As the trigger is not bulkified, I am trying to insert 101 contacts in a single transaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Chr3PdSL4FxrF-UHoWgmlA.png" /></figure><p>Error encountered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TZ8Wemv_cpBAREi-qASLrg.png" /></figure><p>Now, let’s debug using a predefined</p><p>Click on debug &gt; Switch perspective &gt; Analysis</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LwECxw72Nywf64izPyv3Ig.png" /></figure><p>We can identify the issue in the Execution overview, which shows the query executed 99 times.</p><p>Let’s try to resolve this issue by bulkfying the trigger.</p><pre>trigger soqlTrigger on Contact (before insert) {<br>    <br>    if(trigger.isinsert){<br>        /*for(Contact con : Trigger.new){<br>            Account ConAccount = [SELECT id , Name From Account WHERE id =:con.Accountid];<br>            con.LastName = ConAccount.Name;<br>        }*/<br>        set&lt;id&gt; accountids = new set&lt;id&gt;();<br>        for(contact con : trigger.new){<br>            if(con.accountid != null){<br>                accountids.add(con.accountid);<br>            }<br>        }<br>        if(!accountids.isEmpty()){<br>           Map&lt;id,Account&gt; accountMap = new Map&lt;id,Account&gt;([SELECT id, Name FROM account WHERE id IN:accountids]);<br>            if(!accountMap.isEmpty()){<br>                for(Contact c :trigger.new){<br>                    if(c.accountid != null &amp;&amp; accountMap.containsKey(c.Accountid)){<br>                        c.LastName = accountMap.get(c.accountid).Name;<br>                    }<br>                    }<br>                }<br>            }<br>            }<br><br>}</pre><p>First, I am collecting all the account IDs into a set where contacts have account IDs in it. Next, store the account details on the map. At last, I can iterate over contacts, and using a map, I can assign values to the contact LastName.</p><p>After successful execution :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMLWuNcl89NRDoPyivD0dQ.png" /></figure><p><strong>Scenario 3: Recursive Method Causing SOQL 101 Error</strong></p><p>Imagine you have a scenario where insertion or update to bulk records causes a recursive loop try to all the best practices to avoid the loop first and try to avoid using queries inside loops.Here i tried some random example to get this issue triggered .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MfxSAs4LbqjqJIdJTotiow.png" /></figure><p>Error triggered due to recursion and query inside the loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pT9nYkcphDeGJLwgcpv_Xg.png" /></figure><pre>trigger soqlAccount on Account (before insert,after update) {<br> /*  if(trigger.isupdate &amp;&amp; trigger.isAfter){<br>    for(Account acc : Trigger.new) {<br>        // SOQL inside loop - Problem!<br>        List&lt;Contact&gt; contacts = [SELECT Id, LastName <br>                                FROM Contact <br>                                WHERE AccountId = :acc.Id];<br>        <br>        for(Contact con : contacts) {<br>            con.LastName = con.LastName + &#39; Updated&#39;;<br>        }<br>        update contacts; // This will trigger recursion<br>    }<br>    }*/<br>   <br>    // Static flag to prevent recursion<br>    private static Boolean isRunning = false;<br>    <br>    if(!isRunning) {<br>        isRunning = true;<br>        <br>        // Single SOQL query outside loop<br>        List&lt;Contact&gt; allContacts = [SELECT Id, LastName, AccountId <br>                                   FROM Contact <br>                                   WHERE AccountId IN :Trigger.newMap.keySet()];<br>        <br>        List&lt;Contact&gt; contactsToUpdate = new List&lt;Contact&gt;();<br>        for(Contact con : allContacts) {<br>            con.LastName = con.LastName + &#39; Updated&#39;;<br>            contactsToUpdate.add(con);<br>        }<br>        <br>        update contactsToUpdate;<br>        <br>        isRunning = false;<br>    }<br>}</pre><p>Executed without error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FeUvEs9OKUxOh6kTYg5z4A.png" /></figure><p><strong>Scenario 4: Minimize query count by merging them.</strong></p><p>Try to reduce the number of separate SOQL queries if you have a chance merge queries. For example, if a single transaction like enrolling patient, which can have multiple operations like creating prescription, cases, HCP records, etc… So having multiple operations can execute a different number of queries. In this kind of scenario, we can optimize the best possible way of merging queries.</p><pre>Account acc = [Select name, id from Account where id = :accid];<br><br>List&lt;Contact&gt; lstConts = [Select firstName,LastName from Contact where accountid = :accid];</pre><p><strong>After:</strong></p><pre>Account acc = [Select Id, Name, (Select id, firstName,LastName from Contacts) From Account where id = :accid];</pre><p><strong>Scenario -5 : Use @future method if required.</strong></p><p>There can be a scenario where you need to run multiple queries in a single transaction. Where some operations can happen asynchronously executed. In this kind of scenarios, we can move the code to a future method to get extra set of limits.</p><p>Key points:</p><ul><li>Use collections to avoid SOQL inside the for loop.</li><li>Do not use DML statments or SOQL queries inside for loops.</li><li>Bulkify trigger to avoid hitting recursive issue.</li><li>Use future method where asynchronous can be possible to get extra set of limits.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85974f9ef408" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PART-4: SCHEDULED APEX]]></title>
            <link>https://medium.com/@sriharimavireddy.ms/part-4-scheduled-apex-8e17ad4f1ef4?source=rss-83559675068a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e17ad4f1ef4</guid>
            <dc:creator><![CDATA[Sriharimavireddy]]></dc:creator>
            <pubDate>Fri, 31 Jan 2025 01:36:42 GMT</pubDate>
            <atom:updated>2025-02-01T01:01:08.359Z</atom:updated>
            <content:encoded><![CDATA[<p>Scheduled apex is all about running a piece of apex code at a specific time over a set period of time without doing it manually. For Example, If you want to send rejection emails everyday midnight to job seekers whose resumes do not meet the ATS score. This makes tasks easier and uses resources when the org is free without any effect on daily tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*-dbTzGHkO1dsk67Xsk9FMQ.png" /></figure><p>This can be implemented in two different ways:</p><ul><li>Salesforce UI.</li><li>CRON Expression.</li></ul><p><strong>Syntax:</strong></p><pre>Public class SheduleDemo implements schedulable{<br>  public void Execute(SchedulableContext sc){<br>   //Code logic here<br>  }<br>}</pre><ul><li>Execute method is required when implementing the Schedulable interface. It contains the code that Salesforce will run at the scheduled times.</li></ul><p>Example:</p><p>I am trying to update all the account’s names by adding a hello string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eb9lx_6nDnyQ5pBaohRl4Q.png" /></figure><p><strong>Let’s try this using Salesforce UI.</strong></p><p>In UI you need to navigate to Apex classes&gt; now click on Schedule apex button :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-EGFChJo9HX8kUCAsl5F_g.png" /></figure><p>Note: Scheduled UI job updated to 7:00 pm</p><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K2E3maVryXiGVMHD12j7_w.png" /></figure><ul><li>When we have these easy steps of creating a Scheduled apex , why do we have CRON Expressions?</li></ul><p>Using Salesforce UI you can only run jobs based on hours like 6:00 PM and 1:00 AM. What if your business has a scenario where you need to run the logic at 3:15 a.m.?</p><p>This is where <strong>CRON Expressions</strong> are used.</p><p><strong>CRON expressions</strong> are powerful tools for scheduling</p><p>Sample code using CRON Experssion:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jp7vpINRiX7i6nwxMtrclw.png" /></figure><p>Scheduled run at 6:10 pm</p><pre>String cronExpression =&#39;0 38 18 * * ?&#39;;<br>System.schedule(&#39;Display data updated&#39;, cronExpression , new CronUiDemo());</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Oy7MfT04fFper5zBtW11g.png" /></figure><p><strong>Explanation of Cron Expression :</strong></p><p>A CRON expression is made up of six fields:</p><ol><li><strong>Seconds (0–59):</strong> The second of the minute.</li><li><strong>Minutes (0–59):</strong> The minute of the hour.</li><li><strong>Hours (0–23):</strong> The hour of the day.</li><li><strong>Day of Month (1–31):</strong> The day of the month.</li><li><strong>Month (1–12 or JAN-DEC):</strong> The month of the year.</li><li><strong>Day of Week (0–6 or SUN-SAT):</strong> The day of the week.</li></ol><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u7_G4bEmW-IfFtYpQYMhEQ.png" /></figure><p>Limitations:</p><ul><li>You can only have 100 scheduled Apex jobs at one time.</li><li>The maximum number of scheduled Apex executions per a 24-hour period is 250,000 or the number of user licenses in your organization multiplied by 200, whichever is greater.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e17ad4f1ef4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part-3: BATCH APEX]]></title>
            <link>https://medium.com/@sriharimavireddy.ms/part-3-batch-apex-55bb13dfd1c9?source=rss-83559675068a------2</link>
            <guid isPermaLink="false">https://medium.com/p/55bb13dfd1c9</guid>
            <dc:creator><![CDATA[Sriharimavireddy]]></dc:creator>
            <pubDate>Thu, 30 Jan 2025 00:25:42 GMT</pubDate>
            <atom:updated>2025-01-30T22:27:27.339Z</atom:updated>
            <content:encoded><![CDATA[<p>Batch Apex in Salesforce is designed to process large data sets by breaking them into manageable chunks. It’s particularly useful when you need to process records that exceed normal processing limits.</p><ul><li>Operates over small batches/chunks of records.</li><li>Can be scheduled.</li><li>Implement Database.Batchable interface.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*yDbs5AcFLzSMSh-BFsAY9g.jpeg" /></figure><p>Ever tried updating 100,000 records in Salesforce and hit governor limits? That’s where Batch Apex comes to the rescue!</p><p>Think of it like a smart factory assembly line:</p><ul><li>Takes your massive dataset (like 100,000 records).</li><li>Breaks it into smaller, manageable chunks (up to 2,000 records per batch).</li><li>Processes each chunk separately and automatically.</li><li>Handles governor limits for you.</li></ul><p><strong>Syntax:</strong></p><pre>public class BatchDemo implements Database.Batchable{<br>   Start(){<br>   //query all the records to process.<br>   }<br>   execute(){<br>   //Process batch of records from the start<br>   }<br>   Finish(){<br>   //Any post-processing logic  Eg: Send Email<br>   }<br>}</pre><ul><li><strong>Start Method :</strong></li></ul><pre>Public (Database.QueryLocator | Iterable&lt;sObject&gt;) start(Database.BatchableContext bc){}</pre><p>The Start Method is called at the beginning of a batch Apex job. In the start method, you can include code that collects records or objects to pass to the interface method. This method returns either a Database.QueryLocator object or an iterable that contains the records or objects passed to the job.</p><p>If the QueryLocator object is used, the governor limit for the total number of records retrieved by the SOQL query is bypassed. (for example, it can return records up to 50 million records ).</p><ul><li><strong>Execute Method:</strong></li></ul><pre>public void execute(Database.BatchableContext bc,List&lt;sObject&gt;){}<br></pre><p>This method will execute the split batch records that you passed from the start method. Reference to the Database.BatchableContext object and list of Sobjects returned from Database.queryLocator of start method().</p><ul><li><strong>Finish Method:</strong></li></ul><pre>Public void Finish(Database.BatchableContext bc){}</pre><p>The finish method is called after all the batches are processed. For Example, Sending Confirmation Emails or executing post-processing operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*sfyJAL7_oReM2F7XRUWyxg.jpeg" /></figure><p><strong>How to call Batch Apex:</strong></p><pre>Database.executeBatchable( new className(),200);</pre><p>Batch size can be decided in this execution part where the minimum is ‘1’ and the maximum is ‘2000&#39; for the transaction. By default, the value is 200.</p><p><strong>What is the point of having a batch size of 1 for transactions?</strong></p><p>Every transaction has a specific time limit to execute. So there can be a chance for some transactions where the time limit can be exceeded.</p><p>Example operations:</p><ul><li>Complex logics.</li><li>Update triggers.</li><li>External web callouts.</li></ul><p><strong>Example:</strong></p><pre>public class BatchDemoClass implements Database.Batchable&lt;Sobject&gt;{<br>    Public Database.QueryLocator start(Database.BatchableContext bc){<br>        return Database.getQueryLocator(&#39;SELECT id from Account&#39;);<br>    }<br>    public void execute(Database.BatchableContext bc, List&lt;Account&gt; listFromStartMethod){<br>        for(Account acc :listFromStartMethod){<br>            acc.name = &#39;Batch-&#39;+ acc.name;<br>        }<br>        UPDATE listFromStartMethod;<br>    }<br>    public void Finish(Database.BatchableContext bc){<br>        System.debug(&#39;Batch job completed&#39;);<br>    }<br><br>}</pre><p>I have a total of 18 accounts in my org, Here I am trying to run 9 records in each batch.</p><pre>Database.executeBatch(new BatchDemoClass(), 9);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kkdd0EhR27NY0qjNd22riA.png" /></figure><p>Benefits:</p><ul><li>It allows to process 50 Million records in background.</li><li>Best for All long-running processes.</li><li>Chaining is allowed in batch where you need to call another class from the Finish() method.</li></ul><p>PART-4 SCHEDULED APEX:</p><p>todo</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55bb13dfd1c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part-2 : QUEUEABLE APEX]]></title>
            <link>https://medium.com/@sriharimavireddy.ms/part-2-queueable-apex-418f52d75866?source=rss-83559675068a------2</link>
            <guid isPermaLink="false">https://medium.com/p/418f52d75866</guid>
            <dc:creator><![CDATA[Sriharimavireddy]]></dc:creator>
            <pubDate>Wed, 29 Jan 2025 01:46:35 GMT</pubDate>
            <atom:updated>2025-01-29T22:43:32.569Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part-2 : QUEUEABLE APEX</h3><p>Queueable apex is an asynchronous apex method. It can also be called a superset of the future apex. By using this queueable interface, we can process an apex that runs for a long time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N7ICtVO1xwN01zrxmUCAUQ.png" /></figure><p><strong>Syntax of Queueable Apex:</strong></p><pre>public class QueueableExampleClass implements Queueable{<br>      //It should have execute method with parameter QueueableContext<br>      public void execute(QueueableContext inputContext){<br>       //Code logic <br>      }<br>}<br></pre><p>In Future Apex, it’s a method where we can make any method future using @future annotation. When coming to Queueable Apex is a class that follows queueable interface rules. The interface is a set of rules/methods/requirements that a class must follow, Implements are something that will follow/satisfy rules and requirements.</p><p>In easy words, let’s consider Queueable as an Interface, and Interface is a TO-DO LIST. Now, implements will follow that TO DO LIST for our class.</p><p><strong>Conditions to follow:</strong></p><ul><li>Your class should implement Queueable.</li><li>The method should be Named ‘execute’ with the parameter ‘QueueableContext ‘.</li></ul><p><strong>Benefits of Queueable apex when we have a future method?</strong></p><ol><li>Queueable apex supports Non-Primitive type parameters such as SObjects or custom apex types.</li><li>Getting an ID from your job, when you submit your job using System.enqueueJob() method. This will return ID which can be used to track the progress of the operation.</li><li>Chaining of job, we can chain one job to another job which can be useful if your process depends on another process to have run first.</li></ol><p><strong>Example for getting JobId:</strong></p><pre>public class QueueableClass implements Queueable {<br>    public void execute(QueueableContext context){<br>        Account acc = new Account(Name=&#39;Queueable Test&#39;, Phone=&#39;8167569797&#39;);<br>        insert acc;<br>    }<br>}</pre><p>How to execute Queueable Apex:</p><pre>ID jobId =System.enqueueJob(new QueueableClass());<br>system.debug( &#39;job id &#39; + jobId);</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZCsPPeZWfnp5ym6yLcDgXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZmE9babhcVs_wlzbWiMStg.png" /></figure><p><strong>Example for Chaining jobs:</strong></p><p>Scenario — In job 1, Iam trying to create a new account, and in job2 I am trying to delete the records created today.</p><p>Job-1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nm8w9vJukrZwZrhvSoP_aw.png" /></figure><p>Job-2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oI5jqWVcwUyGzDG2HjfTdw.png" /></figure><p>Output:</p><p>Two queueable classes executed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CaEybzl2V2s-syFoZ2214Q.png" /></figure><p>You can observe the order of classes execution</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wLlakZ27TZsPNND-xRmUig.png" /></figure><p>Record created using job1 and deleted using job2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kh2BOO2CqqLSFAZ-F1PrLA.png" /></figure><p><strong>Example queueable allows Non-Primitive types:</strong></p><p>Scenario — When a new Account is inserted trigger will run the Queueable method to create Contact.</p><p>Queueable class accepting a list of newly inserted contacts</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UNjppJekQq7bY7LyO2H1Fw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ypfNZI49iycRey7zpueYg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-iQOsKJQts2GC_cFzxPEhw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*79SAHGXFLx30-h6HHNBrJw.png" /></figure><p>Contact created on insertion of account, which is called from the trigger. Inputs for the Queueable class are provided from the trigger class which are non-primitive parameters (list&lt;account&gt;).</p><h3><strong>Can we define a delay in the execution of a Queueable job?</strong></h3><p>Yes….!!! There is a new optional override that adds queueable jobs to the asynchronous execution queue with a specified minimum delay(0–10 minutes).</p><p>A scenario where this functionality can be used :</p><p>Let’s consider an API call to an external system failure. You might want to retry the call after a brief 5–10-minute delay, hoping the external system is back online.</p><p><strong>Syntax:</strong></p><pre>Integer delayInMinutes = 5;  //(minimum - 0 and maximum -10)<br>ID jobID =System.enqueueJob( new QueueableClass() , delayInMinutes);</pre><p><strong>Simple Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ocV-eK57JykjlImA3vKk6Q.png" /></figure><p>Here, I am trying to insert one account with a delay of 2 minutes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CVWDyE9l0zV92JUcB40qpg.png" /></figure><p>Executed Job with a delay of 2 minutes</p><p>Enqueueing start time :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*of1B2p6wEe1-OrFyzQxyFQ.png" /></figure><p>Executing time :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gvfJ2KGk5MM4whbCzu1unQ.png" /></figure><h3><strong>What if we want to delay all queueable jobs with a specific delay?</strong></h3><p>For this, we do have an option of specifying an org-wide default delay in scheduling queueable jobs. Here, we can set the default delay (1–600 seconds) in scheduling queueable jobs that were scheduled without a delay parameter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tcwTZCrwxlrCFZZMaZEttQ.png" /></figure><p>🤷‍♂️ What if i defined delay in both apex settings and delay parameters in enqueueJob?</p><ul><li>In this case delay parameter in enqueueJob will be considered as priority.</li></ul><h3><strong>Define Stack depth of Chained Queueable Job</strong></h3><p><em>System.AsyncInfo</em> class has methods that help to determine if maximum stack depth and minimum queue delay in async Operations parameters.</p><p>These are the methods in <em>System.asyncInfo</em> class.</p><pre>* hasMaxStackDepth()<br>* getCurrentQueueableStackDepth()<br>* getMaximumQueueableStackDepth()<br>* getMinimumQueueableDelayInMinutes().</pre><p>Example scenario where it can be used:</p><p>Let’s have a scenario where your org is reaching the daily maximum number of asynchronous apex method executions, So here we can use stack depth to terminate the operation when it reaches a specific count.</p><h3><strong>Detecting Duplicate Queueable jobs</strong></h3><p>Reduce resource contention and race conditions by enqueuing only a single instance of your async Queueable job based on the signature. Attempting to add more than one Queueable job to the processing queue with the same signature results in a DuplicateMessageException when you try to enqueue subsequent jobs.</p><p><strong>Using real-world example:</strong></p><p>Imagine you have a task (job) that needs to be done, but you want to make sure only one person is working on it at a time to avoid confusion. This is like having a rule that says “only one person can use the kitchen at a time.”</p><p>The “signature” is like a unique name tag for your task. If you try to assign the same task (with the same name tag) to multiple workers while one is still working on it, the system will say “Sorry, this task is already being worked on” (that’s the DuplicateMessageException).</p><p><strong>Example:</strong></p><p>Trying to execute same enqueue job with same signature :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9JQEYTOkENYecIsvDQe0Q.png" /></figure><p>Output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OvBptUUEacaFktwGvzaf-A.png" /></figure><p><strong>Limitations of Queueable Apex:</strong></p><ul><li>You cannot add more than 50 operations into the queue with the system.enqeueJob in a single transaction.</li><li>Cannot run jobs with millions of records.</li></ul><p>Part -1 : Future Apex</p><p><a href="https://medium.com/@sriharimavireddy.ms/asynchronous-apex-c5405f9b4bef">https://medium.com/@sriharimavireddy.ms/asynchronous-apex-c5405f9b4bef</a></p><p>Part -3: Batch Apex</p><p>To do</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=418f52d75866" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Asynchronous Apex]]></title>
            <link>https://medium.com/@sriharimavireddy.ms/asynchronous-apex-c5405f9b4bef?source=rss-83559675068a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5405f9b4bef</guid>
            <category><![CDATA[asynchronous-apex]]></category>
            <category><![CDATA[apex-progra]]></category>
            <category><![CDATA[future-methods]]></category>
            <category><![CDATA[asynchronous]]></category>
            <dc:creator><![CDATA[Sriharimavireddy]]></dc:creator>
            <pubDate>Tue, 28 Jan 2025 00:18:12 GMT</pubDate>
            <atom:updated>2025-01-29T01:48:53.249Z</atom:updated>
            <content:encoded><![CDATA[<h3>Asynchronous Apex Part-1(Future Method)</h3><p>Asynchronous is something that runs in the background without having you wait for that task to finish. Salesforce allows processes to run in the background without interrupting the user experience.</p><p><strong>Different Types of Asynchronous Apex:</strong></p><ul><li>Future Apex.</li><li>Queueable Apex.</li><li>Batch Apex.</li><li>Scheduled Apex.</li></ul><p><strong>When to use async?</strong></p><ul><li>Things that don’t need user interaction like inputs and button clicks, then move it to asynchronous.</li><li>You can use future methods to isolate DML operations on different Sobject types to prevent mixed DML errors.</li><li>Callouts to external web services or any operation that you would like to run in its own thread.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s-L3phS7DQVRPUBhpQc9yQ.png" /></figure><p><strong>Benefits of using asynchronous apex:</strong></p><p>1. <strong>Enhanced Performance and user experience:</strong> By offloading the time-consuming tasks to the background, ensuring users don’t experience delays or system unresponsiveness.</p><p>2. <strong>Scalability and Handling large data volumes</strong>: While synchronous operations have limited governal limits, asynchronous have an extra set of limits which works as a powerful tool for processing large data volumes and scaling to meet business processes.</p><p>3. <strong>Reliability and error handling:</strong> It has robust error handling and automation capabilities, it can retry failed operations, log errors, and send notifications, ensuring the reliability of your processes and timely resolution of issues.</p><h3>FUTURE APEX</h3><ul><li>When a method is annotated with ‘@future’, then the method is considered to be a future method.</li></ul><pre>global class FutureClass{<br>    @future<br>    public static void MyFutureMethod(Parameters){<br>    //code logic<br>    }<br>}</pre><p>Conditions to follow :</p><ul><li>The future method should be Static and it cannot return anything so the return type should be void.</li><li>Parameters must be primitive data types like String, Integer, or set&lt;id&gt; ... cannot be Non-primitive data types like list&lt;Sobjects&gt;.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*62ySGpZXWkTXE3wWbwRoTA.png" /></figure><p>Why can’t we use Primitive data types in the Future method?</p><p>Let’s consider a scenario, where you targeted an account on which you want to perform some operations. As the future is asynchronous, In the meantime of getting resources free, if any changes are made to the account name then that account is not included in the operation. So to maintain data consistency we use only primitive data types as inputs.</p><ul><li>We can fetch records using primitive values using the following approach:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZubpzBiRes1SKZm-DRnKsw.png" /></figure><p>Example code :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*01TW1RJKr83cQ8oKclisfA.png" /></figure><ul><li>How to Call future method?</li></ul><p>We can call future method by <strong>ClassName.Methodname();</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U_9SpscmCQYeKprrenmLPA.png" /></figure><p>Output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*97VDGVFowO5B9BZ6HO8s1g.png" /></figure><ul><li>How to make callouts to external web services using the Future Method?</li></ul><pre>Global class FutureMethodCallOut{<br>  @future(callout=true)<br>  public static void FutureCallOut(){<br>  //Code logic<br>  }<br>}</pre><ul><li>What is MIXED DML exception?</li></ul><p>When you want to perform two different operations like inserting set-up and non-setup objects in a single transaction we can encounter this error.</p><p>In the below example, i am trying to insert both the account and user in a single transaction:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EoJjlsoL-DIVIE-uBcI97g.png" /></figure><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*pqCtxqgMYvWbiA_DuL0HSQ.png" /></figure><p>To avoid this we can make it into two different methods and make it future.</p><pre>public class MixedDMLClass {<br>    //created a constructor to call both methods from a single method<br>    public MixedDMLClass(){<br>        myMethod();<br>        myUserMethod();<br>    }<br>    @future<br>     public static void myMethod() {<br>        Account a = new Account(Name=&#39;ApexHours&#39;);<br>        insert a;<br>        //Trying to insert Non-setup objects like Account <br>     } <br>    <br>    @future<br>    public static void myUserMethod(){<br>        Profile p = [SELECT Id FROM Profile WHERE Name=&#39;Standard User&#39;];<br>        UserRole r = [SELECT Id FROM UserRole WHERE Name=&#39;CEO&#39;];<br>        User usr = new User(alias = &#39;apexs&#39;, email=&#39;sriharimavireedy.ms@gmail.com&#39;, <br>            emailencodingkey=&#39;UTF-8&#39;, lastname=&#39;Hours&#39;, <br>            languagelocalekey=&#39;en_US&#39;, <br>            localesidkey=&#39;en_US&#39;, profileid = p.Id, userroleid = r.Id,<br>            timezonesidkey=&#39;America/Los_Angeles&#39;, <br>            username=&#39;sriharimavireedy.demo@gmail.com&#39;);<br>        insert usr;<br>        //Inserting Set object like User<br>     }<br>}</pre><pre>MixedDMLClass mixedClass = new MixedDMLClass();</pre><p>Can we now overcome that MIXEDDML error? — — — — -YES……!!!!1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JQnYnAKS4y7griq-U1omXg.png" /></figure><p>🤷‍♂️Can Future method be executed from Future Method?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HqtgyggsNLFt3bNC6ar7Lg.png" /></figure><p>Lets try executing…….!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LN-OvEDXEidI3WEtf7BqEQ.png" /></figure><p>NO….!! We can’t execute one future method from another future method.</p><p><strong>Limitations:</strong></p><ul><li>You cannot call one future method from another future method.</li><li>Can only have primitives as input parameters.</li><li>Order of methods execution is not guaranteed.</li><li>Future methods are indeed limited to fetching 50,000 records in single query.</li><li>No more than 50 methods per Apex invocation.</li><li>The maximum number of future method invocations per a 24-hour period is 25,000 or the number of licenses in your organization multiplied by 200, which is greater.</li><li>@future method called in startest and stoptest do not count againt your limits for the number of queued jobs.</li></ul><h3>QUEUEABLE APEX:</h3><p><a href="https://medium.com/@sriharimavireddy.ms/part-2-queueable-apex-418f52d75866">Part-2 : QUEUEABLE APEX</a></p><p>BATCH APEX:</p><p>TO DO part -3</p><p>SCHEDULED APEX:</p><p>TO DO part -4</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5405f9b4bef" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>