<?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 mahesh chouhan on Medium]]></title>
        <description><![CDATA[Stories by mahesh chouhan on Medium]]></description>
        <link>https://medium.com/@maheshchouhan1995?source=rss-e86a8401fe19------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7SccYzuetgFqtX6YaCvc0g.jpeg</url>
            <title>Stories by mahesh chouhan on Medium</title>
            <link>https://medium.com/@maheshchouhan1995?source=rss-e86a8401fe19------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 23:16:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maheshchouhan1995/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[Lightning Locker Service and Browser Cookies]]></title>
            <link>https://medium.com/@maheshchouhan1995/locker-service-and-browser-cookies-6255ec20d496?source=rss-e86a8401fe19------2</link>
            <guid isPermaLink="false">https://medium.com/p/6255ec20d496</guid>
            <category><![CDATA[cookie-consent]]></category>
            <category><![CDATA[lockerservice]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[community-cloud]]></category>
            <category><![CDATA[lightning-web-component]]></category>
            <dc:creator><![CDATA[mahesh chouhan]]></dc:creator>
            <pubDate>Tue, 23 Jul 2024 11:48:29 GMT</pubDate>
            <atom:updated>2024-07-23T12:11:06.343Z</atom:updated>
            <content:encoded><![CDATA[<h3>Requirement</h3><p>I recently worked on an requirement for implementing a Cookie Consent Banner on our customer’s Experience site. As per Canada Privacy Policy, user consent is required for storing third-party cookies so I built a simple LWC with Banner text and two buttons to capture user response.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-t4PTmVNx3-09kgLfVtCBA.png" /></figure><p>I stored user consent on a cookie , let’s say <strong>“allow_third_party_cookies” </strong>for now on experience site support.google.com and set it to true if user clicked <strong>Close</strong> and otherwise false.</p><h3>Challenge</h3><p>The challenge that we faced that our Org has Lightning Locker service enabled and if I simply add a new cookie through my LWC component, it would add <strong>LSKEY-c$</strong> prefix to cookie name and cookie was stored as <strong>LSKEY-c$allow_third_party_cookies = true </strong>in browser. As per salesforce <a href="https://help.salesforce.com/s/articleView?id=sf.networks_cookies.htm&amp;type=5">documentation</a>, the <strong>LSKEY-c$ </strong>cookie works the same way as a normal cookie and it’s just a way to differentiate between Locker Service cookies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d0ms6SR8SLCYKP5ZXGukYg.png" /></figure><p>But the experience site was hosted on one of the many domains that our customer owns. Which means they wanted to use those set cookies on other websites not built on salesforce experience cloud. Example : <strong>support.google.com</strong> is the experience site and they wanted to use the user consent cookie on <strong>accounts.google.com</strong>.</p><h3>Solution</h3><p>To achieve this we have to move the logic for reading and writing the cookie from LWC component to Head Markup of Experience Site. I added two event listeners getCookies and addCookies under Head markup section.</p><pre>&lt;script type=&quot;text/javascript&quot;&gt;<br> window.addEventListener(&#39;getCookies&#39;, function (event) {<br> event.detail.value = document.cookie;<br> return event;<br> });<br>window.addEventListener(&#39;addCookies&#39;, function(event){<br> let {cookieName, cookieValue, expireInDays, domain} = event.detail;<br> let expires = &quot;&quot;;<br> if (expireInDays) {<br> let date = new Date();<br> date.setTime(date.getTime() + (expireInDays * 24 * 60 * 60 * 1000));<br> expires = &quot;; expires=&quot; + date.toUTCString();<br> }<br> let domainAttribute = domain ? &quot;; domain=&quot; + domain : &quot;&quot;;<br> document.cookie = cookieName + &quot;=&quot; + (cookieValue || &quot;&quot;) + expires + domainAttribute + &quot;; path=/&quot;;<br> });<br>&lt;/script&gt;</pre><p>You can simply get cookies in LWC by firing a custom event.</p><pre>const cookieName = &#39;allow_third_party_cookies&#39;;<br>const getCookieValues = new CustomEvent(&quot;getCookies&quot;, {<br>bubbles: true,<br>composed: true,<br>detail: { value: &quot;&quot; }<br>});<br>this.dispatchEvent(getCookieValues);<br>const documentCookies = getCookieValues.detail.value;<br>var cookieString = RegExp(&quot;&quot;+cookieName+&quot;[^;]+&quot;).exec(documentCookies);<br>let cookieValue = decodeURIComponent(!!cookieString ? cookieString.toString().replace(/^[^=]+./,&quot;&quot;) : &quot;&quot;);</pre><p>Similarly, we can set the cookie as well.</p><pre>const evt = new CustomEvent(&quot;addCookies&quot;, {<br>detail: {<br>  cookieName : &#39;allow_third_party_cookies&#39;,<br>  cookieValue : true,<br>  expireInDays : &#39;7&#39;,<br>  domain : &#39;.google.com&#39;<br>},<br>bubbles: true,<br>composed: true<br>});<br>this.dispatchEvent(evt);</pre><blockquote>Note: Make sure to set bubbles and compose to true.</blockquote><p><strong>allow_third_party_cookies </strong>is not just restricted to support.google.com but can be used for any subdomain like accounts.google.com, analytics.google.com, etc.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6255ec20d496" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CI/CD using Gearset]]></title>
            <link>https://medium.com/@maheshchouhan1995/ci-cd-using-gearset-309332ae8a9c?source=rss-e86a8401fe19------2</link>
            <guid isPermaLink="false">https://medium.com/p/309332ae8a9c</guid>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[deployment]]></category>
            <dc:creator><![CDATA[mahesh chouhan]]></dc:creator>
            <pubDate>Sun, 26 Sep 2021 17:20:08 GMT</pubDate>
            <atom:updated>2021-09-26T17:20:08.801Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Gearset</strong> is a modern DevOps tool for Salesforce. It helps teams to track changes across the Salesforce environment and facilitates the release process.</p><p>You can sign up for a 30 days free <strong>trial</strong> for Gearset <a href="https://app.gearset.com/create-account">here</a>. Once you sign up, Gearset asks you to do a quick <strong>Org Compare</strong>, you can select the option specify that you know your way around the app.</p><p>We will be configuring the following configuration as part of Gearset setup.</p><ol><li>Set up your Salesforce Environments</li><li>Set up Version Control System</li><li>Commit Production Metadata</li><li>Set Up CI/CD Job</li><li>Set Up Unit Testing Job</li><li>Set Up Data Backup Job</li></ol><h4>Set Up Salesforce Environments</h4><ul><li>Navigate to <strong>Salesforce orgs</strong> under My Connections section on the left menu panel.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lw7Al_eI_NB6Vynm" /></figure><ul><li>Click on <strong>Add new Organization </strong>button, keep Salesforce Authentication selected, provide you production username and select Production Organization in the type of org and then click <strong>Authorize</strong> button. It will redirect your to salesforce login screen. Provide your Salesforce credentials and authorize <strong>Gearset Deploy </strong>connected app.</li><li>You will be redirected again to Gearset, provide a Friendly Name as <strong>Production</strong> and click <strong>Ok</strong> button.</li><li>Repeat these steps again to authorize all the required Salesforce environments. I will authorize our <strong>UAT</strong> sandbox also for this demo.</li></ul><h4>Set Up Version Control System</h4><p>I will be using <strong>GitHub</strong> as version control for this demonstration. You can authorize any other VCS like bitbucket, etc.</p><ul><li>Navigate to <strong>Source Control and services</strong> option in My Connections section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9j9dhKZkyifYQVO2" /></figure><ul><li>Click on <strong>Connect to Github</strong>, it will redirect to Github and provide your Github credentials to successfully setup.</li><li>Go to your GitHub home page and click the <strong>New</strong> button on left side under the Repositories section to create a new repository.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QFjuw7y2CUFIuaEU" /></figure><ul><li>Specify a name for your repository, select Private if you want only specific people should be able to access your repository, select <strong>Add a README</strong> file checkbox.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m3DI3d2VCKvNOMRD" /></figure><ul><li>Please check the name of the default branch that will be created. By default, it is the <strong>main</strong> branch but I have modified its name to master by clicking on the <strong>settings</strong> link next to it. Click on <strong>Create Repository</strong>.</li><li><strong>Congrats</strong> ! You will redirect to the main branch on the repository with just README in it.</li></ul><h4>Commit Production Metadata</h4><p>We need to initially move our entire metadata from the <strong>Production</strong> environment to our <strong>master</strong> branch. There are two formats to store Salesforce metadata.</p><p>First is the traditional <strong>MDAPI</strong> format where entire metadata is stored in an <strong>unpackaged</strong> folder in the root directory or <strong>src</strong> folder in the root directory and you have package.xml in the <strong>unpackaged</strong>/<strong>src</strong> folder. You might be familiar with this format if you have used <strong>Eclipse</strong> <strong>IDE</strong>.</p><blockquote>&lt;root directory&gt;/<br>└── unpackaged/</blockquote><blockquote><em>├── package.xml<br>├── objects/</em><br><em> └── SomeObject__c.object<br>├── permissionsets/</em><br> …<br>└── profiles/<br><em> ├── MyProfile.profile</em><br>└── MyOtherProfile.profile</blockquote><p>Second we have <strong>SFDX</strong> folder, where entire metadata is stored in the <strong>force-app</strong> folder and package.xml is present in manifest folder. This format contains the <strong>sfdx-project.json</strong> file at the root. If you are using <strong>VS Code </strong>then you will be more familiar with this metadata format.</p><blockquote>&lt;root directory&gt;/<br><em>├── sfdx-project.json</em><br>└── force-app/<br> └── main/<br> └── default/<br> └── objects/<br> └── Asset/<br> └── Asset.object-meta.xml<br> …<br> …<br> …<br> └── profiles/<br> <em>├── MyProfile.profile-meta.xml</em><br> └── MyOtherProfile.profile-meta.xml</blockquote><p>For this demo, I am going forward with the <strong>SFDX</strong> format. To use SFDX format, we need to commit the <strong>sfdx-project.json</strong> file into our <strong>master</strong> branch so that Gearset can know that you want your metadata to be stored in this format. Without this file, Gearset will store metadata in traditional <strong>MDAPI</strong> format.</p><ul><li>Navigate to your master branch and click on <strong>Add file</strong> button.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EqHfAQYeARPjpBCH" /></figure><ul><li>Name your file as <strong>sfdx-project.json</strong> and paste this content in the file.</li></ul><blockquote>{<br> “packageDirectories”: [<br> { <br> “path”: “force-app”, <br> “default”: true <br> }<br> ],</blockquote><blockquote>“namespace”: “”,<br> “sfdcLoginUrl”: “https://login.salesforce.com”,<br> “sourceApiVersion&quot;: “44.0”<br>}</blockquote><ul><li>Provide a commit message and select <strong>Commit directly to the master branch </strong>and Click <strong>Commit new file</strong>. Please note that <strong>developers should not be committing directly into the master branch</strong> but since we are just setting up the process so we can ignore that for now.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IvAI5yaQIYpFLeHp" /></figure><ul><li>After successful commit, navigate to Gearset and select <strong>Compare and deploy</strong> from the left panel.</li><li>Choose your source metadata location as your <strong>Production</strong> Salesforce environment and target metadata location as your GitHub <strong>master</strong> branch.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yZFrSurSbnI7_jk_" /></figure><ul><li>Change the Metadata comparison filter from <strong>Default Comparison</strong> to <strong>Compare All</strong> to select all metadata to be committed. Click the <strong>Compare Now</strong> button.</li><li>The Next screen will show the list of metadata that Gearset retrieved from source. You can see that all of these are new items because our master does not contain anything. The second bottom half of the screen shows the XML difference. You can click on the <strong>Export All </strong>button at the bottom right to export the list of metadata that are being committed. We will select all metadata and click the <strong>Next</strong> button.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m_mYVD9me6VnNBfa" /></figure><ul><li>Next screen would be Gearset <strong>Problem Analysis</strong> where Gearset runs a couple of quality checks on code as well as metadata. We are going to ignore them for now. Click on the <strong>Next</strong> button. It will ask for confirmation. Click on <strong>Continue to Summary</strong>.</li><li>Provide a Commit message and Click <strong>Commit Changes</strong>. You can notice that the <strong>Validate Deployment</strong> button is inactive because your destination is a git branch not salesforce environment.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*18m6mhTy0t7h9PIg" /></figure><ul><li>Another pop up would appear, select <strong>Deploy</strong>. On successful deployment, you will be redirected to the result screen and you would also receive mail containing deployment report.</li><li>Check your master branch to see the metadata committed. Congrats ! You have successfully created a <strong>master</strong> branch and committed metadata from your <strong>Production</strong> environment.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jSOAuc8kp_yHfOQe" /></figure><h4>Set Up CI/CD Job</h4><p>We are going to set up a deployment job that would run on the UAT environment when any change is pushed to the uat branch. So first, let’s go ahead and create uat branch.</p><ul><li>Navigate to your master branch and click on the master dropdown. Enter uat and then click <strong>Create branch: uat from ‘master’</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T723wqCi4pgFsg6T" /></figure><ul><li>After successful branch creation, you will redirect to uat branch.</li><li>Navigate to <strong>Continuous Integration</strong> under the <strong>Automation</strong> section in the left panel in Gearset and click on <strong>Create Deployment CI Job</strong>.</li><li>Enter the details as mentioned in the image below. Specify your source branch, target org and all the other stuff.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Dui9LC-iEFx4PkG5" /></figure><ul><li>Select <strong>Run tests on the basis of Apex changes in the package</strong> in <strong>Run tests</strong> field.</li><li>Under the <strong>Notification Settings </strong>tab, select only if CI job fails in Send Notifications and provide your email address.</li><li>Under the <strong>Advanced settings</strong>, check <strong>Enable delta CI for this job</strong>. This ensure that only the change that you committed will be deployed to UAT and not the entire branch.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cs3v2PBAFouCVOQq" /></figure><ul><li>Under the <strong>Metadata filter</strong>, specify the metadata that you want Gearset to deploy. Please check some metadata like Custom Application, Custom labels, Custom Metadata, etc. <strong>Note</strong> : <strong><em>You might encounter a case when you have committed some metadata in git but your CI job is not able to deploy that so you need to check if your Metadata filter has that particular metadata selected.</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0dI_GDBH5Cyee9Px" /></figure><ul><li>Click the <strong>Save</strong> button, then click <strong>Add webhook</strong> button and click <strong>finished</strong>. Your CI job is created successfully. If you go to the git repository and check webhooks under settings, you can see that Gearset webhook is created successfully. This webhook will notify Gearset when any change is pushed to the branch so that it can run CI job.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NwpEbR3sM5cexw8a" /></figure><ul><li>Gearset will run a sample CI deployment job but will not deploy anything. You can also verify the same by navigating to <strong>Deployment Status </strong>in your UAT sandbox.</li><li>Congrats ! We have successfully created a CI job to automate deployment. Similarly, you can setup a CI job for production by specifying source as master branch and target as Production org.</li></ul><p>Let’s test this out, I am going to commit a sample apex class demonstrating Stack Implementation and its test class to see if our deployment job is working fine. I will be following the git-flow. Please check this <a href="https://medium.com/@maheshchouhan1995/continuous-integration-ci-continuous-delivery-cd-fundamentals-3de82931c21e">article</a> if you are not familiar with git-flow.</p><p>I have created a feature branch named <strong>feature/US-001</strong> from <strong>uat</strong> where I will be committing my changes. I have deliberately written one wrong assertion so that our CI job should fail. As soon as I create the pull request to uat, it will trigger CI job in Gearset and you can see the failure on pull request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Lf0AMGruBxLEpUKO" /></figure><p>You can check the failure by clicking on the details link and clicking on <strong>View Errors </strong>button. This is showing clearly that the test class method has failed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o2PrArcgqAvjKs9z" /></figure><p>I need to make an additional commit to fix this failure and then we can view on PR that all checks have passed. This is just a validation check and you can verify the same by navigating to <strong>Deployment Status</strong> in UAT sandbox. You can rerun CI job in Gearset easily but you want to run it from GitHub, you can make an empty commit using this command</p><blockquote><strong><em>git commit — allow-empty -m ‘Rerun validation’</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JBukLnRip2Nt_xKr" /></figure><p>Now we need to merge the pull request and that would trigger an actual deployment job to UAT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VjxLJAeuqdnPVzAd" /></figure><p>Congrats ! We have successfully moved our changes to the UAT environment using Gearset. Similarly If i create pull request from <strong>uat</strong> to <strong>master</strong>, Gearset will run validation on <strong>Production</strong> environment and merging the pull request will run Deployment job on <strong>Production</strong> environment.</p><p>Here is the link my Github <a href="https://github.com/meta-mahesh-chouhan/demo-gearset">repo</a>. I have made this repo public for reference purposes.</p><h4>Conclusion</h4><p>Gearset is smart DevOps solution which makes it easy to setup CI/CD for your salesforce environment. This is an <strong>Admin friendly</strong> tool and does not required that much coding knowledge. We will continue our discussion on Gearset in next blog. You can let me know in comments if you have any queries or suggestions. Keep learning !!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/0*YjQcrXkLACXLcVfD.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=309332ae8a9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Continuous Integration (CI)/ Continuous Delivery (CD) Fundamentals]]></title>
            <link>https://medium.com/@maheshchouhan1995/continuous-integration-ci-continuous-delivery-cd-fundamentals-3de82931c21e?source=rss-e86a8401fe19------2</link>
            <guid isPermaLink="false">https://medium.com/p/3de82931c21e</guid>
            <category><![CDATA[continuous-delivery]]></category>
            <category><![CDATA[gitflow]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <dc:creator><![CDATA[mahesh chouhan]]></dc:creator>
            <pubDate>Sat, 25 Sep 2021 14:34:54 GMT</pubDate>
            <atom:updated>2021-09-25T14:34:54.671Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*5p_5FFvy7V3rnzpl.png" /></figure><p><strong>Continuous Integration(CI)</strong> is a process in which developers regularly check in their code in a <strong>version control system</strong> (like GitHub, bitbucket) and automated tests run on each check in to ensure it is bug free.</p><p>Now, the question arises why exactly do we need CI processes in Salesforce ? What is wrong with the traditional change set ? They seem to be working fine, right !</p><h4>Version Control System</h4><p>Let’s consider a scenario where you are modifying a page layout and deploying your changes from your <strong>DEV</strong> sandbox to your <strong>UAT</strong> sandbox, probably a full copy of your production. There are chances that you may override the changes done by other developers on the same page layout if your sandbox is not refreshed recently. We need a mechanism to ensure that we are only migrating our modifications and not removing any other developers’ changes. That’s where the version control system comes into play.</p><figure><img alt="Difference Checker in Source Control" src="https://cdn-images-1.medium.com/max/1024/0*H8k-XRsxPUNKIFmZ" /></figure><p>It helps you to visualise the changes. The same cannot be done using change set. Surely we can check the audit trail to identify who modified the page layout but it does not provide clarity about the exact change.</p><p>This is just one scenario, there are a couple of other issues with change sets like traversing the list of metadata, going back and forth to add each type of metadata in the change set. That is one tedious task. I can switch to CI/CD just to avoid that, no more reasons required.</p><p>We also want to use version control because it acts as a <strong>source of truth</strong> which was earlier our Production environment.</p><h4>Automated Test and Checks</h4><p>Now, let’s look at the second aspect of it i.e. automated tests. These automated tests are executed through what we call builds, jobs or pipelines that basically depend on what tool you are using <strong>Jenkins</strong>(job) or <strong>Bitbucket</strong>(pipeline). These tests run on each check in or commit of your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Oi72R6s5pqJzeQlVIeHCw.png" /></figure><p>These automated tests can include a simple validation similar to that of change set or you can run apex tests to ensure that all tests are passing and you have your minimum test coverage percentage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Xxqil6ykJ4_bk8rq" /><figcaption>This image shows a unit test failing in apex test job</figcaption></figure><p>Continuous Integration ensures that you can only merge your changes to the version control system if these tests are passed.</p><p>Apart from automated test jobs, we have deployment jobs which ensures that our code is successfully moved to the next environment for further testing. This aspect comes under Continuous Delivery/Continuous Deployment.</p><p>Another important aspect of CI/CD is Static Code Analysis. We should integrate tools like Apex PMD and Sonarqube which would run code checks on Apex classes. These code checks ensure the quality of the code. You can checkout <a href="https://pmd.github.io/latest/pmd_rules_apex.html">Apex PMD</a> documentation. It’s pretty awesome !</p><h4>Gitflow</h4><p>Since we will be using version control, we need to decide on a git workflow. GitFlow is the most commonly used git workflow.</p><figure><img alt="GitFlow Diagram" src="https://cdn-images-1.medium.com/max/905/0*RC93oqa6k7cvjeOf.png" /></figure><p>This workflow has majorly four branches :</p><ol><li><strong>Master/Main</strong> <strong>:</strong> This is the first branch created when you create a new repository. This branch contains actual Production code. <strong><em>Developers should not be making direct commits in this branch</em></strong> and all the changes must go through pull requests following proper procedure.</li><li><strong>Hotfix</strong> <strong>:</strong> This branch is created when you want to fix something on Production. This branch should be created from master and then merged to master as well as develop; to prevent bug from reappearing in the next release. <strong><em>Developers can directly commit in this branch. </em></strong>Once this branch is merged, it can be deleted.</li><li><strong>Develop : </strong>This branch is created initially from the master branch and is an exact copy. This branch get merges from feature and hotfix branch. <strong><em>Developers should not commit directly in this branch</em></strong> and all changes must come through pull requests. Develop branch acts as integration branch to integrate code from multiple feature branches.</li><li><strong>Feature</strong> : This is the actual git branch where developers should be implementing new functionalities. This branch is created from develop and then merged again to develop. <strong><em>Developers can directly commit to this branch.</em></strong>Once this branch is merged, it can be deleted.</li><li><strong>Release</strong> : This branch is created when you want to release your code to production. This branch is created from develop and then merged into production and master. When release is done, this branch is deleted. Each release merge into master creates a version tag specifying the current version of your software.</li></ol><p>Let’s look at this with an example. Suppose for this quarter, your team needs to implement an integration with amazon AWS so you have different user stories in different epics to build this integration piece by piece.</p><p>Every developer who will be working on their user story will create a new feature branch from the last develop. He will be implementing the functionality in his personal developer sandbox. He will be committing the metadata changes done as part of that user story into the feature branch. Once that is done, he will create a pull request from his feature branch to develop so that his changes can be merged into the develop branch.</p><p>Since we have CI/CD in-place, once the pull request is created automated tested would run on that PR checking the code quality, validation job to check if modified change can be deployed successfully and check if there are any apex test class failures because of this change. Once all the checks are passed, we are good to merge the pull request and that would move our changes into the develop branch. The merge commit into the develop branch would trigger another CI job to deploy our changes to the next(<strong>UAT</strong>) environment so that QA can test there. Every developer will follow the same procedure and build this integration piece by piece.</p><p>Once all the user stories are moved to UAT by the end of quarter and our integration is working fine. We will create a new release branch from develop and if some bugs are identified, we will commit those changes directly in the release branch. Each commit on the release branch will trigger a validation job on Production environment. Once the release is done, the release branch will be merged into master and then into develop. The merge commit into the master branch will run a CI job that will deploy the changes to the <strong>Production</strong> environment.</p><p>Congrats ! We have successfully released a brand new integration but wait, we just noticed that there is a new bug introduced due to this release. No issue, we will create a new <strong>hotfix</strong> branch from master, commit our changes there, check if validation jobs are passing successfully and then merge PR to master again triggering the CI job to deploy changes again to the <strong>Production</strong> environment.</p><p>So to summarise, we have 2 main branches</p><p><strong>Master</strong> which is linked to Production environment. Any open PR targeting master will run a validation job on the Production environment. Once PR is merged, Deployment job will run in the Production environment.</p><p><strong>Develop</strong> which is linked to UAT sandbox. Any open PR targeting develop will run a validation job on the UAT environment. Once PR is merged, Deployment job will run in the UAT environment.</p><p><strong>Feature</strong>, <strong>release</strong> and <strong>hotfix</strong> will be created as per requirement and deleted after their use.</p><p>This is just the basic git-flow. Your organisation can come up with their own variation if you have multiple salesforce environments like this</p><p><strong>Master</strong> <strong>-&gt;</strong> <strong>Production Environment</strong></p><p><strong>UAT -&gt; UAT Sandbox</strong></p><p><strong>Develop -&gt; Integration Sandbox</strong></p><h4>Conclusion</h4><p>CI/CD has some strong advantages over the traditional change sets and it help to streamline the development process and ensure smooth and bug free deliveries.</p><p>Hope you guys like the blog ! Let me know in the comments if you guys have any query.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xI9Foz_NRl4cyxnX" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3de82931c21e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CI/CD using Bitbucket Pipeline for Salesforce — Part 2]]></title>
            <link>https://medium.com/@maheshchouhan1995/ci-cd-using-bitbucket-pipeline-for-salesforce-part-2-8fe982823e02?source=rss-e86a8401fe19------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fe982823e02</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[bitbucket]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[mahesh chouhan]]></dc:creator>
            <pubDate>Tue, 02 Jun 2020 10:45:09 GMT</pubDate>
            <atom:updated>2020-06-02T10:45:09.411Z</atom:updated>
            <content:encoded><![CDATA[<h3>CI/CD using Bitbucket Pipeline for Salesforce — Part 2</h3><p>Before moving forward, let’s review the tools we will be using:</p><h3>Docker</h3><p>Docker provide virtual environments similar to our local environment.Whenever we create a pipeline, it always run on an virtual environment which is defined by a docker image. You can create your own docker image or just use the one, I got from one of the <a href="https://hub.docker.com/u/mklinski">Salesforce </a>Demos.If you look at the docker image, we will notice that It adds all the tools required for our pipeline like java and apache ANT.</p><h3>Force.com Migration Tool</h3><p>It is a very powerful tool to retrieve and deploy metadata from Salesforce orgs.We can also run Apex Tests using Ant Migration Tool. Install it from this <a href="https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_install.htm">link</a>. It comes with an build.xml where all the Ant Targets are defined. Apache ANT itself is a widely using Automation tool.</p><h3>Bitbucket Pipelines</h3><p>Bitbucket Pipelines is an integrated CI/CD service, built into Bitbucket. It allows you to automatically build, test and even deploy your code, based on a configuration file in your repository. To create pipeline, we need to configure <a href="https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html">bitbucket-pipelines.yml</a> in the root of the repository.</p><ul><li>Navigate to our Dev Repository and click on <strong>Pipelines </strong>on the left panel then click <strong>Docker </strong>and <strong>commit file</strong>. This will commit a sample pipeline file. You can see that a build has started in pipeline section but it will fail. We will fix this later.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RvmEOTKVXJ5j9viI" /></figure><ul><li>Click on<strong> Branches</strong> in left pane. Click on <strong>Create Branch</strong> at the top right.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s69JFYkn5-2Re7xi" /></figure><ul><li>Specify Branch Name as <strong>feature/pipeline-setup</strong>, leave other fields as it is and click <strong>Create</strong> button. The name of the branch is with respect to git flow which I will cover in some other post.</li><li>Click branch locally using Source Tree or Git CLI. I am more of a CLI guy.</li><li>Open <strong>bitbucket-pipelines.yml </strong>using any text editor and paster following content into this file.</li></ul><blockquote>image:<br> name: mklinski/salesforce<br>pipelines:<br> branches:<br> feature/*:<br> — step:<br> script:<br> — ant -buildfile build/build.xml checkDeploy -Dsfdc.username=$SFDC_USERNAME -Dsfdc.password=$SFDC_PASS$SFDC_TOKEN -Dsfdc.serverurl=https://$SFDC_SERVERURL<br> master:<br> — step:<br> script:<br> — ant -buildfile build/build.xml deployCode -Dsfdc.username=$SFDC_USERNAME -Dsfdc.password=$SFDC_PASS$SFDC_TOKEN -Dsfdc.serverurl=https://$SFDC_SERVERURL</blockquote><ul><li>The image tag specifies the docker image which will be used for running pipeline. Docker provides a virtual environment where we will execute our commands.</li><li>You can see from the above code that we are running two types of ant commands. For feature types of branches, we are running checkDeploy and master branch, we are running deployCode. These commands are defined by Force.com Ant Migration Tool.</li><li>Although we have used the build.xml in our <strong>bitbucket-pipelines.yml </strong>file, we have not actually committed our build.xml. Create a build folder and add build.xml and paste following code.</li></ul><blockquote>&lt;<strong>project</strong> name=”Deploy SFDC metadata” default=”deployEmptyCheckOnly” basedir=”..” xmlns:sf=”antlib:com.salesforce”&gt;</blockquote><blockquote>&lt;<strong>taskdef</strong> uri=”antlib:com.salesforce”<br> resource=”com/salesforce/antlib.xml”<br> classpath=”${basedir}/build/lib/ant-salesforce.jar”/&gt;</blockquote><blockquote>&lt;<strong>property</strong> file=”${basedir}/build/build.properties”/&gt;<br> &lt;<strong>property</strong> environment=”env”/&gt;</blockquote><blockquote>&lt;<strong>target</strong> name=”deployCode”&gt;<br> &lt;<strong>echo</strong> level=”info”&gt;Performing the deploy&lt;/<strong>echo</strong>&gt;<br> &lt;<strong>sf:deploy</strong><br> username=”${sfdc.username}”<br> password=”${sfdc.password}”<br> serverurl=”${sfdc.serverurl}”<br> deployRoot=”${basedir}/src”<br> pollWaitMillis=”${sfdc.pollWaitMillis}”<br> maxPoll=”${sfdc.maxPoll}”/&gt;<br> &lt;/<strong>target</strong>&gt;</blockquote><blockquote>&lt;<strong>target</strong> name=”checkDeploy”&gt;<br> &lt;<strong>echo</strong> level=”info”&gt;Testing the deploy&lt;/<strong>echo</strong>&gt;<br> &lt;<strong>sf:deploy</strong><br> checkOnly=”true”<br> logType=”Debugonly”<br> username=”${sfdc.username}”<br> password=”${sfdc.password}”<br> serverurl=”${sfdc.serverurl}”<br> deployRoot=”${basedir}/src”<br> pollWaitMillis=”${sfdc.pollWaitMillis}”<br> maxPoll=”${sfdc.maxPoll}”<br> testLevel=”RunLocalTests”&gt;<br> &lt;/<strong>sf:deploy</strong>&gt;<br> &lt;/<strong>target</strong>&gt;<br>&lt;/<strong>project</strong>&gt;</blockquote><ul><li>Create build.properties and paste following code.</li></ul><p>sfdc.maxPoll = 100<br>sfdc.pollWaitMillis = 100000</p><ul><li>Create a new folder lib inside build and paste ant-salesforce.jar there that you must have received on downloading Foce.com Migration Tool.</li><li>Now it’s time to add the actual Salesforce Metadata that we want to deploy. Create an src folder and the src folder from this <a href="https://bitbucket.org/maheshchouhanbitbucket/dev/src/24e91e679a603bf187fc9dc151ed51a2215cde0d/?at=feature%2Fpipeline-setup">repository</a>.I have written a class for Stack Implementation and test class for that.</li><li>Our repository should look like this.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/0*giAj73eT9x21ytpp" /></figure><ul><li>Now, just commit the changes and push it to remote repository.It will trigger a new build, which will fail with this error Attribute ‘username’ cannot be an empty string It occurred because we have not defined the $SFDC_USERNAME variables that we are using in our pipeline file. These variables need to be defined at Repository level.</li><li>Navigate to <strong>Dev</strong> Repository and Click on <strong>Repository Settings</strong> and then <strong>Repository Variables</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hAuoe7kl0BK2Hy6j" /></figure><ul><li>Add SFDC_SERVERURL, SFDC_TOKEN, SFDC_PASS and SFDC_USERNAME variables and populate their values.Since this is Dev Repository, I am going to connect it to Dev Sandbox.</li><li>Navigate to Pipeline page and click on <strong>Rerun </strong>button on top. Your Build will pass successfully.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-ce9mNT1rw3Q8kOP" /></figure><ul><li>You can also verify the same by loggin into your dev sandbox and checking deployment status in Quick Find box.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DVsXaZDt9VcKPCyW" /></figure><ul><li>As our build, we can go ahead and merge this feature branch into master. Since we need to promote our changes to UAT, we need to merge into master branch of UAT Repository but first, we need to define repository variables on UAT repository.</li><li>Now create a pull request to merge feature branch from Dev to master branch of UAT.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aPKara9n7v56NF1y" /></figure><ul><li>Assign any reviewer if you want and then merge the pull request. After that, we can one build start in pipeline section but this time actual code will be deployed to UAT and not just deployment check.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FGZv-NYceIflrOFs" /></figure><ul><li>Congratulations ! We have successfully promoted our code to UAT. Similarly after testing is done, we can create another pull request from feature branch of dev to master of production to deploy our code to Salesforce Production Environment.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fe982823e02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up Salesforce Environment]]></title>
            <link>https://medium.com/@maheshchouhan1995/setting-up-salesforce-environment-c4ac75bf1bec?source=rss-e86a8401fe19------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4ac75bf1bec</guid>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[bitbuket]]></category>
            <category><![CDATA[salesforce]]></category>
            <dc:creator><![CDATA[mahesh chouhan]]></dc:creator>
            <pubDate>Tue, 02 Jun 2020 07:20:44 GMT</pubDate>
            <atom:updated>2020-06-02T10:38:49.511Z</atom:updated>
            <content:encoded><![CDATA[<h3>CI/CD using Bitbucket Pipeline for Salesforce — Part 1</h3><p>First, we need to set up different Salesforce Environments (Dev, UAT and Production) using which we are going to move changes up in the hierarchy.</p><p>Generally, Developers work on Dev Sandboxes and after any particular feature is implemented, those changes are propagated upwards to UAT where QA does the testing. After getting approvals from QA, these changes are then propagated to Production.</p><p>Usually, there is an integration environment between Dev Sandbox and UAT where multiple Devs integrate their work to make sure it’s not affecting other Dev’s work but for this demo, we are not considering integration environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c7y_gazvTrsRUqk_" /></figure><p>Let’s begin.</p><ul><li>Sign up for a 30 days <a href="https://www.salesforce.com/form/signup/freetrial-platform/">free tria</a>l of Salesforce Environment which will act as our production environment.</li><li>After logging into the production environment, open Setup by clicking on the Gear icon at top right and click <strong>Setup</strong>. Then enter <strong>Sandbox </strong>in Quick Find box in the left and then click <strong>Sanboxes</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mBSZsp13oE6fBYUK" /></figure><ul><li>Click on the new Sandbox and specify the name as <strong>Dev </strong>and create from <strong>Production. </strong>Under the <strong>Sandbox License</strong> section, click <strong>next </strong>button under the Developer column.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3b0qe-EbVGVggBT6" /></figure><ul><li>Leave the <strong>Apex class</strong> field blank and click the <strong>create </strong>button.A job will be started and you will receive an email when the sandbox is created and ready for use.</li><li>UAT Salesforce Environment are generally of Full Sandbox but our 30 day trial version does not come with Full Sandbox license so we are going to create UAT environment of Developer Sandbox. Create a <strong>UAT </strong>sandbox using the above steps.</li></ul><h3>Setting up Bitbucket Repository</h3><p>We are going to set up three bitbucket repositories corresponding to each Salesforce environment. The UAT will be a fork repository of Production and Dev will be a fork of UAT. Fork repository is a copy of origin repository but it provides a great way to track changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KLgrBYBGZybXvYxb" /></figure><p>Let’s roll.</p><ul><li>Sign up for a free <a href="https://bitbucket.org/account/signup/">Bitbucket </a>account.</li><li>Once you login into your bitbucket account, click on <strong>+</strong> in the left bar and then select <strong>Repository.</strong></li><li>Provide Repository Name as Production and Project as Salesforce. Uncheck Private Repository checkbox,select <strong>Yes, with a tutorial</strong> in <strong>Include a README</strong> picklist and then click the Create<strong> Repository</strong> button.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LEzhQH3q-bRMA_px" /></figure><ul><li>Once the repository is created, you will be redirected to the Production Repository. Click on<strong> +</strong> icon at the left side bar and click <strong>Fork this repository</strong>. Select Salesforce as Project and provide UAT in Name field.</li><li>Similarly, fork UAT repository to create Dev repository.</li><li>Everything is set up. We are ready to build pipelines.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4ac75bf1bec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>