<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-623632917225910672</atom:id><lastBuildDate>Tue, 31 Mar 2026 18:11:28 +0000</lastBuildDate><category>LWC</category><category>salesforce</category><category>Lightning Web Component</category><category>Ligthning</category><category>CDC</category><category>Change Data Capture</category><category>asynchronous</category><category>callbacks</category><category>javascript</category><category>lightning</category><category>methods</category><category>promise</category><category>web components</category><category>Apex Method Imperatively</category><category>Apex Trigger</category><category>Async</category><category>Async Apex Trigger</category><category>Extensions</category><category>LMS</category><category>Lightning Message Service</category><category>Message Channel</category><category>Platform Events</category><category>Service Component</category><category>Subscription Channel</category><category>Trigger</category><category>VS Code</category><category>VSCode</category><category>asyn</category><category>async/await</category><category>await</category><category>case team roles</category><category>case team salesforce</category><category>case teams</category><category>event message</category><category>external source</category><category>external system</category><category>mule</category><category>mulesoft</category><category>pagination</category><category>plugins</category><category>predefined case teams</category><category>sequential</category><category>wiring</category><title>Salesforce Tips, Tricks, and Knowledge</title><description></description><link>https://tandonprateek.blogspot.com/</link><managingEditor>noreply@blogger.com (Prateek Tandon)</managingEditor><generator>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-8096152788163796196</guid><pubDate>Thu, 05 May 2022 19:25:00 +0000</pubDate><atom:updated>2022-05-05T12:27:54.105-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">asyn</category><category domain="http://www.blogger.com/atom/ns#">async/await</category><category domain="http://www.blogger.com/atom/ns#">asynchronous</category><category domain="http://www.blogger.com/atom/ns#">await</category><category domain="http://www.blogger.com/atom/ns#">callbacks</category><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">lightning</category><category domain="http://www.blogger.com/atom/ns#">LWC</category><category domain="http://www.blogger.com/atom/ns#">methods</category><category domain="http://www.blogger.com/atom/ns#">promise</category><category domain="http://www.blogger.com/atom/ns#">salesforce</category><category domain="http://www.blogger.com/atom/ns#">sequential</category><category domain="http://www.blogger.com/atom/ns#">web components</category><title>Understanding of Async/Await in LWC - Extension to Promise</title><description>&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;&lt;span&gt;&lt;span face=&quot;lato, lato, &amp;quot;helvetica neue&amp;quot;, helvetica, arial, sans-serif&quot; style=&quot;background-color: white; font-size: 16px; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;&lt;span&gt;&lt;span face=&quot;lato, lato, &amp;quot;helvetica neue&amp;quot;, helvetica, arial, sans-serif&quot; style=&quot;background-color: white; font-size: 16px; text-align: justify;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;&lt;span&gt;&lt;span face=&quot;lato, lato, &amp;quot;helvetica neue&amp;quot;, helvetica, arial, sans-serif&quot; style=&quot;background-color: white; font-size: 16px; text-align: justify;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEibnXqM2th9IlHLrIXJF8lhQ--E7EyJ_DooCVsyjFxrQAlkwtMNxVQEy5RXOUpczuMzS6a9jY6KTxgl_HcH57aJWaGcf7BheqTpndHp-zQvRyx0fGlXibmN4y2ux5J56HgCC3wBIQRPeEOIjHpvMxfqPuOy6KoNOBiwGSUSPSm92Wf_IuN2-6pZBHf0&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;280&quot; data-original-width=&quot;600&quot; height=&quot;149&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEibnXqM2th9IlHLrIXJF8lhQ--E7EyJ_DooCVsyjFxrQAlkwtMNxVQEy5RXOUpczuMzS6a9jY6KTxgl_HcH57aJWaGcf7BheqTpndHp-zQvRyx0fGlXibmN4y2ux5J56HgCC3wBIQRPeEOIjHpvMxfqPuOy6KoNOBiwGSUSPSm92Wf_IuN2-6pZBHf0&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;&lt;span&gt;&lt;span face=&quot;lato, lato, &amp;quot;helvetica neue&amp;quot;, helvetica, arial, sans-serif&quot; style=&quot;background-color: white; font-size: 16px; text-align: justify;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;
  &lt;span style=&quot;font-family: helvetica;&quot;&gt;&lt;span&gt;&lt;span face=&quot;lato, lato, &amp;quot;helvetica neue&amp;quot;, helvetica, arial, sans-serif&quot; style=&quot;background-color: white; font-size: 16px; text-align: justify;&quot;&gt;In the last post, we discussed about &lt;i&gt;Promise&lt;/i&gt; function&amp;nbsp;&lt;/span&gt;&lt;span face=&quot;lato, lato, helvetica neue, helvetica, arial, sans-serif&quot;&gt;&lt;a href=&quot;https://tandonprateek.blogspot.com/2022/04/how-to-chain-asynchronous-actions-in-lwc.html&quot; target=&quot;_blank&quot;&gt;How to chain Asynchronous actions in LWC using Promise?&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;span face=&quot;lato, lato, &amp;quot;helvetica neue&amp;quot;, helvetica, arial, sans-serif&quot; style=&quot;background-color: white; font-size: 16px;&quot;&gt;While they provide easy control to Asynchronous JavaScript, but Async/Await
    which builds on Promises&amp;nbsp;&lt;/span&gt;&lt;span face=&quot;lato, lato, &amp;quot;helvetica neue&amp;quot;, helvetica, arial, sans-serif&quot; style=&quot;background-color: white; font-size: 16px;&quot;&gt;allowing them to be used in a way that much more closely resembles
    synchronous JavaScript.&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b style=&quot;font-size: 16px;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;Async&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;
  &lt;span style=&quot;font-family: helvetica;&quot;&gt;&lt;span face=&quot;lato, lato, helvetica neue, helvetica, arial, sans-serif&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;It is simply a keyword we put in front of a function
      definition.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span face=&quot;lato, lato, &amp;quot;helvetica neue&amp;quot;, helvetica, arial, sans-serif&quot; style=&quot;background-color: white; font-size: 16px;&quot;&gt;Async functions are instances of
    the&amp;nbsp;AsyncFunction&amp;nbsp;constructor.&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;async &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;function&lt;/span&gt; performAction() {
   &lt;span style=&quot;color: #888888;&quot;&gt;// do some asynchronous action&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;result of an action&#39;&lt;/span&gt;;
}
&lt;/pre&gt;&lt;/div&gt;

&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;An Async function always returns a Promise. That promise will contain the value that you defined.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;If you look at the below code script&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;function&lt;/span&gt; start() {
    console.log(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;start&#39;&lt;/span&gt;);
    console.log(performAction());
    console.log(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;stop&#39;&lt;/span&gt;);
}

start();
&lt;/pre&gt;&lt;/div&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;You might expect the below result&lt;/span&gt;&lt;/p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;start
result of an action
stop
&lt;/pre&gt;&lt;/div&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;But in reality the result will be&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/span&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;start
stop
result of an action
&lt;/pre&gt;&lt;/div&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;This is because &lt;i&gt;performAction()&lt;/i&gt; was executed asynchronously.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;Now, to make the above code work like synchronously or to execute all calls in sequential order we need to use Await function.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;Await&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;The await expression causes the async function to pause until a Promise is returned for the async function. So, in simple words we are essentially telling our code to wait for the result of the asynchronous function to complete going any further.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;&lt;i&gt;await&lt;/i&gt; always expects a &lt;i&gt;Promise&lt;/i&gt; from the &lt;i&gt;async&lt;/i&gt; function, and parses the result automatically.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;Lets consider the above code snippet&lt;/span&gt;&lt;/p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;async &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;function&lt;/span&gt; performAction() {
   &lt;span style=&quot;color: #888888;&quot;&gt;// do some asynchronous action&lt;/span&gt;
   &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;result of an action&#39;&lt;/span&gt;;
}

async &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;function&lt;/span&gt; start() {
    console.log(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;start&#39;&lt;/span&gt;);
    console.log(await performAction());
    console.log(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;stop&#39;&lt;/span&gt;);
}

start();
&lt;/pre&gt;&lt;/div&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;Now the result will be&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/span&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;start
result of an action
stop
&lt;/pre&gt;&lt;/div&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;This is because we are waiting the function &lt;i&gt;performAction()&lt;/i&gt; to be completed before proceeding further.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;NOTE: await can only be used within Async function.&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;u&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;Usage in LWC&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;&lt;u&gt;Problem Statement&lt;/u&gt;&amp;nbsp;: I need to re-render the validation message whenever the user checks Another amount as a radio button, but for me the DOM is not getting rendered properly on UI. So, I need to make a wait before I check for the selected radio button and checks the validity and reset it. So, to make that happen I need to put my change action in async/await.&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;Below is the code snippet:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;payment.html&lt;/span&gt;&lt;/p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;&amp;lt;!--&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @description       : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @author            : @tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @group             : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @last modified on  : 04-15-2022&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @last modified by  : @tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;--&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
	&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-grid slds-gutters slds-var-m-bottom_small&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
		&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-col slds-size_1-of-3 slds-nowrap&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
			{labels.component.amountToPay}
		&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
		&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-col&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
			&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-radio-group&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;name=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;amountToPay&quot;&lt;/span&gt;
                &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{labels.component.amountToPay}&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;variant=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;label-hidden&quot;&lt;/span&gt;
				&lt;span style=&quot;color: #0000cc;&quot;&gt;options=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{amountToPayOptions}&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;value=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{amountToPaySelection}&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;type=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;radio&quot;&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;onclick=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleAmountToPayChange}&lt;/span&gt;
				&lt;span style=&quot;color: #0000cc;&quot;&gt;onchange=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleAmountToPayChange}&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-var-m-bottom_small requiredInput&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;required&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
			&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-radio-group&amp;gt;
			&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-input&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;type=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;number&quot;&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;name=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;anotherAmount&quot;&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Another Amount&quot;&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;variant=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;label-hidden&quot;&lt;/span&gt;
				&lt;span style=&quot;color: #0000cc;&quot;&gt;value=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{anotherAmount}&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;min=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;1&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onfocus=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleAnotherAmountFocus}&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;onchange=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleAnotherAmountChange}&lt;/span&gt;
				&lt;span style=&quot;color: #0000cc;&quot;&gt;formatter=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;currency&quot;&lt;/span&gt; 
                &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;inputAmount anotherAmount requiredInput&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;required=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{isAnotherAmountRequired}&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
			&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-input&amp;gt;
		&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
	&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;payment.js&lt;/span&gt;&lt;/p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;/**
 * @description       : 
 * @author            : @tandonprateek
 * @group             : 
 * @last modified on  : 05-05-2022
 * @last modified by  : @tandonprateek
**/
import { LightningElement } from &#39;lwc&#39;;

const ANOTHER_AMOUNT_OPTION = &#39;anotherAmount&#39;;
const AMOUNT_DUE_TODAY_OPTION = &#39;amountDueToday&#39;;


export default class Payment extends LightningElement {

    labels = {
        toast: {
            processingErrorTitle: &#39;Processing Error&#39;
            , validationErrorTitle: &#39;Input Validation Error&#39;
            , validationErrorMessage: &#39;Please provide values for all required fields&#39;
        },
        component: {
            paymentHeader: &#39;Payment&#39;
            , amountToPay: &#39;Amount to Pay&#39;
            , amountDueToday: &#39;Amount Due Today &#39;
            , remainingBalance: &#39;Remaining Balance &#39;
            , anotherAmount: &#39;Another Amount&#39;
        }
    }

    amountToPaySelection;
    anotherAmount;
    isAnotherAmountRequired = false;

    connectedCallback() {
        this.amountToPaySelection = AMOUNT_DUE_TODAY_OPTION
    }

    /**
        This method will wait for the Promise to be resolved and will then reset the validity.
    **/
    async handleAmountToPayChange(event) {
        this.amountToPaySelection = event.detail.value;
        const anotherAmountField = this.template.querySelector(&#39;.anotherAmount&#39;);
        if(this.amountToPaySelection !== ANOTHER_AMOUNT_OPTION) {
            this.anotherAmount = undefined;
            await Promise.resolve();
            anotherAmountField.reportValidity();
        } else {
          anotherAmountField.focus();
          anotherAmountField.reportValidity();
        }
        this.isAnotherAmountRequired = this.amountToPaySelection === ANOTHER_AMOUNT_OPTION;
    }
    
    handleAnotherAmountChange(event) {
        const value = event.detail.value;
        this.anotherAmount = value;
    }
    
    handleAnotherAmountFocus(event) {
        this.amountToPaySelection = ANOTHER_AMOUNT_OPTION;
        this.isAnotherAmountRequired = this.amountToPaySelection === ANOTHER_AMOUNT_OPTION;
    }
    
    get amountToPayOptions() {
        const theOptions = [];
        theOptions.push({ label: this.labels.component.amountDueToday, value: AMOUNT_DUE_TODAY_OPTION});
    
        let balanceLabel = this.labels.component.remainingBalance;
    
        theOptions.push({ label: balanceLabel, value: &#39;remainingBalance&#39;});
        
        theOptions.push({ label: this.labels.component.anotherAmount, value: ANOTHER_AMOUNT_OPTION });
    
        return theOptions;
    }

}
&lt;/pre&gt;&lt;/div&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;518&#39; height=&#39;266&#39; src=&#39;https://www.blogger.com/video.g?token=AD6v5dyCYkElFWwbH5PR0DdZgFaVwSgEE12zliPifB8vLQe7Zns1AXJLKNbCsSQzDqRvWY_Y2TQPUt88b2jjj3LPXw&#39; class=&#39;b-hbp-video b-uploaded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;br /&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;Error Handling&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: helvetica;&quot;&gt;To handle error we will be using old &lt;b&gt;&lt;i&gt;try/catch&lt;/i&gt;&lt;/b&gt; block.&lt;/span&gt;&lt;/p&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;async function doSomething() {
   // do something asyncronous
   return &#39;something&#39;;
}

async function start() {
    try {
        console.log(&#39;start&#39;);
        console.log(await performAction());
        console.log(&#39;end&#39;);
    } catch(e) {
        console.error(e);
    } finally {
        console.log(&#39;Do something no matter what&#39;);
    }
}

start();
&lt;/pre&gt;&lt;/div&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
</description><link>https://tandonprateek.blogspot.com/2022/05/understanding-of-asyncawait-in-lwc.html</link><author>noreply@blogger.com (Prateek Tandon)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEibnXqM2th9IlHLrIXJF8lhQ--E7EyJ_DooCVsyjFxrQAlkwtMNxVQEy5RXOUpczuMzS6a9jY6KTxgl_HcH57aJWaGcf7BheqTpndHp-zQvRyx0fGlXibmN4y2ux5J56HgCC3wBIQRPeEOIjHpvMxfqPuOy6KoNOBiwGSUSPSm92Wf_IuN2-6pZBHf0=s72-c" height="72" width="72"/><thr:total>0</thr:total><georss:featurename>Vancouver, BC, Canada</georss:featurename><georss:point>49.2827291 -123.1207375</georss:point><georss:box>20.972495263821152 -158.27698750000002 77.59296293617885 -87.9644875</georss:box></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-6630862785027688668</guid><pubDate>Tue, 19 Apr 2022 19:05:00 +0000</pubDate><atom:updated>2022-05-05T12:26:17.277-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">asynchronous</category><category domain="http://www.blogger.com/atom/ns#">callbacks</category><category domain="http://www.blogger.com/atom/ns#">javascript</category><category domain="http://www.blogger.com/atom/ns#">lightning</category><category domain="http://www.blogger.com/atom/ns#">LWC</category><category domain="http://www.blogger.com/atom/ns#">methods</category><category domain="http://www.blogger.com/atom/ns#">promise</category><category domain="http://www.blogger.com/atom/ns#">salesforce</category><category domain="http://www.blogger.com/atom/ns#">web components</category><title>How to chain Asynchronous actions in LWC using Promise?</title><description>&lt;p&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgB5Cr8dHjp0lF8h8lvchvnRKYmhELyATuY5hhBhc7cIqEoFFqXroOgXIyFiaxqFkvQZAl4bFSXaNsRVvq7QwDS3hRzttxpo3mopFg11sb94tNF-KEqWXc9s_V2Q3jzeE3DSgHeJd_QWI93e_H39lIUdgcecN9TKPqNamfdQHOb78A7o7F6u77RvxKw&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; data-original-height=&quot;400&quot; data-original-width=&quot;780&quot; height=&quot;230&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgB5Cr8dHjp0lF8h8lvchvnRKYmhELyATuY5hhBhc7cIqEoFFqXroOgXIyFiaxqFkvQZAl4bFSXaNsRVvq7QwDS3hRzttxpo3mopFg11sb94tNF-KEqWXc9s_V2Q3jzeE3DSgHeJd_QWI93e_H39lIUdgcecN9TKPqNamfdQHOb78A7o7F6u77RvxKw=w487-h230&quot; width=&quot;487&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;;&quot;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;
  &lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;;&quot;&gt;As we are aware that Javascript can interpret only one statement at a time.
    With this, Javascript also doesn&#39;t face concurrency issue like other
    language faces while executing threads. Having said that, in Javascript, you
    can execute &quot;Asynchronous Methods&quot;. These Asynchronous Methods are
    &quot;Callbacks, Promises, Async/Await&quot;.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  First, let&#39;s understand the difference between Callbacks and Promises before
  using Asynchronous actions in LWC.
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;
  Callbacks:
&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  A callback is a function that is to be executed after another function has
  finished executing. Async callbacks are functions that are passed as
  arguments. and when that function is called it will start executing code in
  the background. When the background code finishes running, it calls the
  callback function to let you know the work is done. We use these callbacks
  because we want to avoid executing things out of order. If we want to wait for
  something in JavaScript, we need to use a callback.
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  Let&#39;s make Pizza from scratch using callbacks:
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;
  Synchronous Code:
&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;!--HTML generated using hilite.me--&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
  &lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;const&lt;/span&gt; makePizza &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; () &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; {

  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;const&lt;/span&gt; pizzaBase &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; makePizzaBase();

  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;const&lt;/span&gt; veggies &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; chopVeggies();

  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;const&lt;/span&gt; spreads &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; makePizzaSpreads();

  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;const&lt;/span&gt; cheese &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; grateCheese();

  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;const&lt;/span&gt; pizza &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; preparePizza(pb, veg, spread, cheese);

  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; pizza;

 }

 makePizzaBase() &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; () &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; {

  &lt;span style=&quot;color: #888888;&quot;&gt;//do something&lt;/span&gt;

 }
&lt;/pre&gt;
&lt;/div&gt;

&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  This synchronous makePizza() function runs in order, one function after
  another but what if we had a function that needed to be run first and other
  functions couldn&#39;t be running until after this function finishes. Let’s think
  of making pizza from scratch, you can’t put the veggies, spreads, and cheese
  on the pizza base until it’s made so you must wait until it&#39;s done. With
  synchronous code, it doesn’t wait it just does it. So, to fix this issue we
  have to Async callbacks.
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;
  Asynchronous Code:
&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;!--HTML generated using hilite.me--&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
  &lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;const&lt;/span&gt; makePizza &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; () &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; {

  makePizzaBase(&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;function&lt;/span&gt;(){

   chopVeggies(&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;function&lt;/span&gt;(..arguments){

    makePizzaSpreads(&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;function&lt;/span&gt;(&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;…&lt;/span&gt;arguments){

     grateCheese(&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;function&lt;/span&gt;(&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;…&lt;/span&gt;arguments){

      preparePizza(){

       &lt;span style=&quot;color: #888888;&quot;&gt;//pizza is ready&lt;/span&gt;

      }

     });

    });

   });

  });
&lt;/pre&gt;
&lt;/div&gt;

&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  Let’s consider the above asynchronous code which has a lot of code to execute.
  This code execution can cause an issue because we can have enough nested
  callbacks inside one another. This leads to what we call callback hell.
  Callback hell can puzzle the code with bugs that are illusory. For this
  reason, we need a way to get rid of so many nested callbacks.
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;
  Promises&lt;/b&gt;:
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  A promise is a returned object where you attach callbacks, instead of passing
  callbacks into a function. You can attach the callback after the successful
  completion of a task is called, .then(). inside this, you can pass a callback.
  Promises allow us to avoid callback hell by chaining multiple .then() on each
  other which avoids nested callbacks and a cleaner code. For the failure of
  completing a task, you can pass it through a .catch() block.
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  Let’s convert the above asynchronous callback code to Promise:
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;!--HTML generated using hilite.me--&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
  &lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;const&lt;/span&gt; makePizza &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; () &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; {

  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; makePizzaBase()

   .then(veggies &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; chopVeggies(vegetables))

   .then(pizzaSpreads &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; makePizzaSpreads(sauces))

   .then(cheese &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; grateCheese(cheese))

   .then(pizza &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; constructPizza());

  &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;catch&lt;/span&gt;((bad pizza));

 }
&lt;/pre&gt;
&lt;/div&gt;

&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  In the above code, we turned our code into Promise. First, we will make the
  pizza base and on completion, we are returning the promise that will be passed
  to the next callback. Next, we did chaining on other functions that will
  execute one after the other in order by using .then(), making an async
  function. As we have observed that code looks cleaner and we avoided callback
  hell.
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;
  How we can use Promise in LWC:
&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  A promise can have three stages
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  - &lt;b&gt;Pending&lt;/b&gt; - Default state, not fulfilled, not rejected.
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  - &lt;b&gt;Fulfilled&lt;/b&gt; - Operation completed.
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  - &lt;b&gt;Rejected&lt;/b&gt; - Operation failed.
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;
  Syntax :
&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;var promise =
  new Promise(function(resolve, reject){
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  &lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;
    &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/span&gt;//do something
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;});
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px; min-height: 15px;&quot;&gt;
  &lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;
  Example:
&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;
  promiseExample.html
&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;!--HTML generated using hilite.me--&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
  &lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;&amp;lt;!--&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @description       : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @author            : @tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @group             : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @last modified on  : 04-19-2022&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @last modified by  : @tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;--&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-input&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;type=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;text&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Input1&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;value=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{val1}&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onchange=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{val1Change}&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-input&amp;gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-input&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;type=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;text&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Input2&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;value=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{val2}&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onchange=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{val2Change}&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-input&amp;gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;br/&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-button&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;variant=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;brand&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Demo Promise Example&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;title=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onclick=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{executePromise}&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-m-left_x-small&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-button&amp;gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;Promise status : {status}&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;

&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;
  promiseExample.js
&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;!--HTML generated using hilite.me--&gt;
&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
  &lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;/**&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt; * @description       : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt; * @author            : @tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt; * @group             : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt; * @last modified on  : 04-19-2022&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt; * @last modified by  : @tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;**/&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; { LightningElement } from &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;lwc&#39;&lt;/span&gt;;

&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;export&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;default&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;class&lt;/span&gt; PromiseExample &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;extends&lt;/span&gt; LightningElement {
    val1; 
    val2;
    status;

    val1Change(event) {
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.val1&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; event.target.value;
    }

    val2Change(event) {
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.val2&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; event.target.value;
    }
    
  promiseDemoExample(arg1, arg2) {
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;new&lt;/span&gt; Promise((resolve, reject) &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; {
      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; (arg1 &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; arg2) resolve();
      &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt; reject();
    });
  }

  executePromise() {
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.promiseDemoExample(&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.val1, &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.val2)
      .then((result) &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; {
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.status &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Resolved and Fulfilled&quot;&lt;/span&gt;;
      })
      .&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;catch&lt;/span&gt;((result) &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; {
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.status &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Rejected and Failed&quot;&lt;/span&gt;;
      });
  }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;The promiseDemoExample method returns a Promise which will resolve in the
  future. When we call the promiseDemoExample&amp;nbsp;method with 2 parameters, it
  will check if they are equal, if they are equal promise will resolve, or else
  it will reject the promise.
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px 0px 2px; min-height: 19px;&quot;&gt;
  &lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  In executePromise method when a promise is resolved or rejected it will call
  either .then() method (when resolved) or .catch() method (when rejected).&lt;span class=&quot;Apple-converted-space&quot;&gt;&amp;nbsp;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px 0px 2px; min-height: 19px;&quot;&gt;
  &lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  Every time a promise is resolved it will go in .then() block and when a
  promise is rejected it will go into .catch() block. Along with it, you can also
  create .finally() block which will execute no matter what happens to promise.
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px 0px 2px; min-height: 19px;&quot;&gt;
  &lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  In .then() or .catch() method you can chain other promise as well. Using
  chaining, you can execute the asynchronous method in sequential order.
&lt;/p&gt;
&lt;p class=&quot;p2&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px 0px 2px; min-height: 19px;&quot;&gt;
  &lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;b&gt;
  For Example:
&lt;/b&gt;&lt;/p&gt;
&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;
&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;executePromise() {
    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.promiseDemoExample(&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.val1, &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;this&lt;/span&gt;.val2)
      .then((result) &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; {
        &lt;span style=&quot;color: #888888;&quot;&gt;//do something or add new promise&lt;/span&gt;
      })
      .then((result) &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; {
        &lt;span style=&quot;color: #888888;&quot;&gt;//do something or add new promise&lt;/span&gt;
      })
      .&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;catch&lt;/span&gt;((result) &lt;span style=&quot;color: #333333;&quot;&gt;=&amp;gt;&lt;/span&gt; {
        &lt;span style=&quot;color: #888888;&quot;&gt;//rejected&lt;/span&gt;
      });
  }
&lt;/pre&gt;&lt;/div&gt;

&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;
  &lt;br /&gt;
&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;In the next post, I will discuss the &lt;a href=&quot;https://tandonprateek.blogspot.com/2022/05/understanding-of-asyncawait-in-lwc.html&quot; target=&quot;_blank&quot;&gt;Async/Await&lt;/a&gt; methods, as these methods are extensions of Promises. So stay tuned till then.&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;p1&quot; style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; margin: 0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
</description><link>https://tandonprateek.blogspot.com/2022/04/how-to-chain-asynchronous-actions-in-lwc.html</link><author>noreply@blogger.com (Prateek Tandon)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEgB5Cr8dHjp0lF8h8lvchvnRKYmhELyATuY5hhBhc7cIqEoFFqXroOgXIyFiaxqFkvQZAl4bFSXaNsRVvq7QwDS3hRzttxpo3mopFg11sb94tNF-KEqWXc9s_V2Q3jzeE3DSgHeJd_QWI93e_H39lIUdgcecN9TKPqNamfdQHOb78A7o7F6u77RvxKw=s72-w487-h230-c" height="72" width="72"/><thr:total>0</thr:total><georss:featurename>Vancouver, BC, Canada</georss:featurename><georss:point>49.2827291 -123.1207375</georss:point><georss:box>20.972495263821152 -158.27698750000002 77.59296293617885 -87.9644875</georss:box></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-1960409946551466188</guid><pubDate>Thu, 14 Apr 2022 17:42:00 +0000</pubDate><atom:updated>2022-04-19T12:06:56.841-07:00</atom:updated><title>Dynamic Tree Structure with LWC and Apex</title><description>&lt;p&gt;
  &lt;span face=&quot;&amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif&quot; style=&quot;background-color: white; color: #4a4a4a; letter-spacing: 0.3px;&quot;&gt;In this post, I am going to share a component that I built while playing
    with LWC(Lightning Web Components). This is a simple LWC component with most
    logic handled by Apex.&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span face=&quot;&amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif&quot; style=&quot;background-color: white; color: #4a4a4a; letter-spacing: 0.3px;&quot;&gt;While playing, I decided to create a sample tree structure which I think is
  useful to get the proper hierarchy for the records having self-relationship or
  child relationships. In this example, I want to display a complete view of all
  Accounts as well as a hierarchy for accounts within a single tree itself.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot;background-color: white; background-repeat: no-repeat; box-sizing: border-box; color: #4a4a4a; font-family: &amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif; letter-spacing: 0.3px; line-height: 1.6; margin: 0px 0px 30px;&quot;&gt;
  With LWC, I am able to make this tree structure minimum lines of code in my
  HTML component by using&amp;nbsp;&lt;span style=&quot;color: #383838; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, monospace; white-space: pre;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, monospace; white-space: pre;&quot;&gt;lightning-tree&lt;/span&gt;&lt;span style=&quot;color: #383838; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, monospace; white-space: pre;&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style=&quot;color: maroon; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, monospace; white-space: pre;&quot;&gt;lightning-tree&lt;/span&gt;&lt;span style=&quot;color: #383838; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, monospace; white-space: pre;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;letter-spacing: 0.3px;&quot;&gt;. With the help of this component, it displays the related contacts, and
    cases for an Account. I have also created a self lookup relationship on
    Account which will have a hierarchy of Accounts, and this hierarchy will be
    displayed in the same tree structure along with other relationships.&lt;/span&gt;
&lt;/p&gt;
&lt;p style=&quot;background-color: white; background-repeat: no-repeat; box-sizing: border-box; color: #4a4a4a; font-family: &amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif; letter-spacing: 0.3px; line-height: 1.6; margin: 0px 0px 30px;&quot;&gt;
  &lt;span style=&quot;letter-spacing: 0.3px;&quot;&gt;Below is the code:&lt;/span&gt;
&lt;/p&gt;
&lt;div style=&quot;background-color: white; line-height: 18px; white-space: pre;&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt; &lt;span face=&quot;&amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif&quot; style=&quot;letter-spacing: 0.3px; line-height: 1.6; margin: 0px 0px 30px;&quot;&gt;DynamicTreeStructureController.cls&lt;/span&gt;&lt;/p&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; line-height: 18px; white-space: pre;&quot;&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
    &lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;/**&lt;/span&gt;
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@description&lt;/span&gt;       : 
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@author&lt;/span&gt;            : &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@tandonprateek&lt;/span&gt;
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@group&lt;/span&gt;             : 
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@last&lt;/span&gt; modified on  : &lt;span style=&quot;color: #4400ee; font-weight: bold;&quot;&gt;04&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2022&lt;/span&gt;
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@last&lt;/span&gt; modified by  : &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #333333;&quot;&gt;**/&lt;/span&gt;
public &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;with&lt;/span&gt; sharing &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;DynamicTreeStructureController&lt;/span&gt; {
    public DynamicTreeStructureController() {

    }

    private static Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; result;
    private static Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, Id&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; childIdMap;

    &lt;span style=&quot;color: #333333;&quot;&gt;/**&lt;/span&gt;
    Static Method to be fed &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@wire&lt;/span&gt; &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; LWC
    &lt;span style=&quot;color: #333333;&quot;&gt;*/&lt;/span&gt;
    &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@AuraEnabled&lt;/span&gt;(cacheable&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;true)
    public static List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; getAccounts(){
        result &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;();
        childIdMap &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, Id&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;();
        Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, Account&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; accMap &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, Account&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;([SELECT Id, Name FROM Account WHERE ParentId &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; null]);
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;!&lt;/span&gt;accMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;isEmpty()){
            startFetchingAccountDetails(accMap);
        }
        System&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;debug(JSON&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;serialize(result));
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; result&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;values();
    }

    &lt;span style=&quot;color: #333333;&quot;&gt;/**&lt;/span&gt;
    &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; Recursion method to get &lt;span style=&quot;color: #007020;&quot;&gt;all&lt;/span&gt; levels of accounts &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;and&lt;/span&gt; their related records
    &lt;span style=&quot;color: #333333;&quot;&gt;*/&lt;/span&gt;
    private static List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; startFetchingAccountDetails(Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, Account&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; accMap){
        Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; parentStructure &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; gatherAllAccountInformation(accMap);

        &lt;span style=&quot;color: #333333;&quot;&gt;//&lt;/span&gt;attach the first level to actual result &lt;span style=&quot;color: black; font-weight: bold;&quot;&gt;and&lt;/span&gt; rest will auotmatically link
        &lt;span style=&quot;color: #333333;&quot;&gt;//&lt;/span&gt;due to &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;pass&lt;/span&gt; by reference way
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(result &lt;span style=&quot;color: #333333;&quot;&gt;==&lt;/span&gt; null &lt;span style=&quot;color: #333333;&quot;&gt;||&lt;/span&gt; result&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;isEmpty()){
            result&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;putAll(parentStructure);
        }
        Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, Account&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; childMap &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, Account&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;([SELECT Id, Name, DemoLight12__Account__c FROM Account WHERE DemoLight12__Account__c &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;: accMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;keySet()]);
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(childMap &lt;span style=&quot;color: #333333;&quot;&gt;!=&lt;/span&gt; null &lt;span style=&quot;color: #333333;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;!&lt;/span&gt;childMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;isEmpty() &lt;span style=&quot;color: #333333;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; childMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;size() &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;){
            Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, Id&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; accChildIdMap &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, Id&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;();
            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt;(Id childAccountId : childMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;keySet()){
                Account child &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; childMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get(childAccountId);
                childIdMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;put(child&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Id, child&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;DemoLight12__Account__c);
            }

            &lt;span style=&quot;color: #333333;&quot;&gt;//&lt;/span&gt;run this method recursively to get &lt;span style=&quot;color: #007020;&quot;&gt;all&lt;/span&gt; child levels&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;
            List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; childStructure &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; startFetchingAccountDetails(childMap);
            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt;(TreeStructure child : childStructure){
                TreeStructure parent &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; parentStructure&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get(childIdMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get(child&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;name));
                parent&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;items&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;add(child);
            }
        }
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; parentStructure&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;values();
    }

    &lt;span style=&quot;color: #333333;&quot;&gt;/**&lt;/span&gt;
    &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; Method to gather &lt;span style=&quot;color: #007020;&quot;&gt;all&lt;/span&gt; information &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt; &lt;span style=&quot;color: #007020;&quot;&gt;all&lt;/span&gt; accounts recieved
    &lt;span style=&quot;color: #333333;&quot;&gt;*/&lt;/span&gt;
    private static Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; gatherAllAccountInformation( Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, Account&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; accMap){
        Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; result &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;();

        Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Contact&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; accConMap &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new  Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Contact&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;();
        Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Opportunity&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; accOppCMap &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Opportunity&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;();
        Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Case&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; conCaseCMap &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new Map&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Id, List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Case&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;();

        &lt;span style=&quot;color: #333333;&quot;&gt;//&lt;/span&gt;gather &lt;span style=&quot;color: #007020;&quot;&gt;all&lt;/span&gt; contacts
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt;(Contact con : [SELECT Id, Name, AccountId FROM Contact WHERE AccountId &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;: accMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;keySet()]){
            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;!&lt;/span&gt;accConMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;containsKey(con&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;AccountId)){
                accConMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;put(con&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;AccountId, new List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Contact&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;());
            }
             accConMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get(con&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;AccountId)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;add(con);
        }

        &lt;span style=&quot;color: #333333;&quot;&gt;//&lt;/span&gt;gather &lt;span style=&quot;color: #007020;&quot;&gt;all&lt;/span&gt; cases
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt;(Case cas : [SELECT Id, CaseNumber, ContactId FROM Case WHERE ContactId &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;: accConMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;keySet()]){
            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;!&lt;/span&gt;conCaseCMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;containsKey(cas&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;ContactId)){
                conCaseCMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;put(cas&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;ContactId, new List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;Case&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;());
            }
            conCaseCMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get(cas&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;ContactId)&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;add(cas);
        }

        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt;(Id accountId : accMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;keySet()){
            Account acc &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; accMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get(accountId);
            TreeStructure accStructure &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new TreeStructure(acc&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;name, accountId, false, null);

            &lt;span style=&quot;color: #333333;&quot;&gt;//&lt;/span&gt;add &lt;span style=&quot;color: #007020;&quot;&gt;all&lt;/span&gt; contacts &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; present
            &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(accConMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;containsKey(accountId)){
                TreeStructure conStructure &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new TreeStructure(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Contacts&#39;&lt;/span&gt;, &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Contacts&#39;&lt;/span&gt;, false, null);
                &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt;(Contact con :  accConMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get(accountId)){
                    conStructure&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;items&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;add( new TreeStructure(con&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Name, con&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Id, false, null));
                    &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(conCaseCMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;containsKey(con&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Id)){
                        TreeStructure caseStructure &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new TreeStructure(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Cases&#39;&lt;/span&gt;, &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;Cases&#39;&lt;/span&gt;, false, null);
                        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;for&lt;/span&gt;(Case cas : conCaseCMap&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;get(con&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Id)){
                            caseStructure&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;items&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;add( new TreeStructure(cas&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;CaseNumber, cas&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;Id, false, null));
                        }
                        conStructure&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;items&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;add(caseStructure);
                    }
                }
                accStructure&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;items&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;add(conStructure);
            }

            result&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;put(accountId, accStructure);
        }
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;return&lt;/span&gt; result;
    }
}
&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; line-height: 18px; white-space: pre;&quot;&gt;&lt;span style=&quot;font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px;&quot;&gt;
 &lt;/span&gt;&lt;span face=&quot;&amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif&quot; style=&quot;font-size: 1.25rem; letter-spacing: 0.3px; line-height: 1.6; margin: 0px 0px 30px;&quot;&gt;TreeStructure.cls&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; line-height: 18px; white-space: pre;&quot;&gt;&lt;br /&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, monospace; font-size: 12px; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
    &lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;/**&lt;/span&gt;
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@description&lt;/span&gt;       : 
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@author&lt;/span&gt;            : &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@tandonprateek&lt;/span&gt;
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@group&lt;/span&gt;             : 
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@last&lt;/span&gt; modified on  : &lt;span style=&quot;color: #4400ee; font-weight: bold;&quot;&gt;04&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2022&lt;/span&gt;
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@last&lt;/span&gt; modified by  : &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #333333;&quot;&gt;**/&lt;/span&gt;
public &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;TreeStructure&lt;/span&gt;{
    &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@AuraEnabled&lt;/span&gt; public String label;
    &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@AuraEnabled&lt;/span&gt; public String name;
    &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@AuraEnabled&lt;/span&gt; public Boolean expanded;
    &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@AuraEnabled&lt;/span&gt; public List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; items;
    public TreeStructure(String label, String name, Boolean expanded, List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; items){
        this&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;label &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; label;
        this&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;name &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; name;
        this&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;expanded &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; expanded;
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;(items &lt;span style=&quot;color: #333333;&quot;&gt;!=&lt;/span&gt; null &lt;span style=&quot;color: #333333;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; items&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;size() &lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;0&lt;/span&gt;){
            this&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;items &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; items;
        }&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;else&lt;/span&gt;{
            this&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;items &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; new List&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;TreeStructure&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;();
        }
    }
}
&lt;/pre&gt;
  &lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; line-height: 18px; white-space: pre;&quot;&gt;&lt;span face=&quot;&amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif&quot; style=&quot;font-size: 1.25rem; letter-spacing: 0.3px; line-height: 1.6; margin: 0px 0px 30px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; line-height: 18px; white-space: pre;&quot;&gt;&lt;span face=&quot;&amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif&quot; style=&quot;font-size: 1.25rem; letter-spacing: 0.3px; line-height: 1.6; margin: 0px 0px 30px;&quot;&gt; &lt;/span&gt;&lt;span face=&quot;&amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif&quot; style=&quot;letter-spacing: 0.3px; line-height: 1.6; margin: 0px 0px 30px;&quot;&gt; dynamicTreeStructure.html&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; line-height: 18px; white-space: pre;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;    &lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
      &lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;--&lt;/span&gt;
  &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@description&lt;/span&gt;       : 
  &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@author&lt;/span&gt;            : &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@tandonprateek&lt;/span&gt;
  &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@group&lt;/span&gt;             : 
  &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@last&lt;/span&gt; modified on  : &lt;span style=&quot;color: #4400ee; font-weight: bold;&quot;&gt;04&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2022&lt;/span&gt;
  &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@last&lt;/span&gt; modified by  : &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #333333;&quot;&gt;--&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;template&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;lightning&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;card title&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Tree Components with mutliple nested Accounts and other child records of Accounts&quot;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;div class&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-m-top_medium slds-m-bottom_x-large&quot;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;!&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;--&lt;/span&gt; Simple &lt;span style=&quot;color: #333333;&quot;&gt;--&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;template &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt;:true&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;{accounts&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;data}&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;div class&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-p-around_medium lgc-bg&quot;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;&lt;/span&gt;lightning&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;tree items&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;{accounts&lt;span style=&quot;color: #333333;&quot;&gt;.&lt;/span&gt;data} header&lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Accounts&quot;&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;lightning&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;tree&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;/&lt;/span&gt;template&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;/&lt;/span&gt;div&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;/&lt;/span&gt;lightning&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;card&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span style=&quot;color: #333333;&quot;&gt;&amp;lt;/&lt;/span&gt;template&lt;span style=&quot;color: #333333;&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
    &lt;/div&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; font-family: &amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif; letter-spacing: 0.3px; line-height: 1.6; margin: 0px 0px 30px; white-space: pre;&quot;&gt; dynamicTreeStructure.js&lt;span style=&quot;font-family: inherit;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit; font-size: large;&quot;&gt;  &lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; line-height: 18px; white-space: pre;&quot;&gt;&lt;span style=&quot;font-family: inherit; font-size: medium;&quot;&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
      &lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #333333;&quot;&gt;/**&lt;/span&gt;
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@description&lt;/span&gt;       : 
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@author&lt;/span&gt;            : &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@tandonprateek&lt;/span&gt;
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@group&lt;/span&gt;             : 
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@last&lt;/span&gt; modified on  : &lt;span style=&quot;color: #4400ee; font-weight: bold;&quot;&gt;04&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color: #333333;&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: #0000dd; font-weight: bold;&quot;&gt;2022&lt;/span&gt;
 &lt;span style=&quot;color: #333333;&quot;&gt;*&lt;/span&gt; &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@last&lt;/span&gt; modified by  : &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #333333;&quot;&gt;**/&lt;/span&gt;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; { LightningElement, wire } &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;lwc&#39;&lt;/span&gt;;
&lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;import&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;getAccounts&lt;/span&gt; &lt;span style=&quot;color: #0e84b5; font-weight: bold;&quot;&gt;from&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;@salesforce/apex/DynamicTreeStructureController.getAccounts&#39;&lt;/span&gt;;

export default &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;class&lt;/span&gt; &lt;span style=&quot;color: #bb0066; font-weight: bold;&quot;&gt;Dynamic_Tree_Structure&lt;/span&gt; extends LightningElement {
  &lt;span style=&quot;color: #555555; font-weight: bold;&quot;&gt;@wire&lt;/span&gt;(getAccounts) accounts;
}
&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/span&gt;
&lt;b style=&quot;color: #4a4a4a; font-family: &amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif; letter-spacing: 0.3px;&quot;&gt;Important:&lt;/b&gt;&lt;span face=&quot;&amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif&quot; style=&quot;color: #4a4a4a; letter-spacing: 0.3px;&quot;&gt; Above solution is tested with 4 level hierarchy of Accounts. We need to consider the &lt;/span&gt;&lt;p style=&quot;color: #4a4a4a; font-family: &amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif; letter-spacing: 0.3px; line-height: 1.6;&quot;&gt;&lt;span face=&quot;&amp;quot;Source Sans Pro&amp;quot;, Helvetica, Arial, sans-serif&quot; style=&quot;letter-spacing: 0.3px; line-height: 1.6;&quot;&gt;governor limits and might need to modify the logic as per the requirements.&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyFop3_c5n1dd3rzP1LN2YsuIIO6CxNdII4Dm-BiptybXCZbWyMZMdDD16yHlYcD2a6R3YlDzhJ2LUDFJ_xOkiWBOUAsU0bwhoah5IjZ9NDqPT2j9uX7vXZJawih9pWzu3xDiVEg7RZmJJimdjYRFeLV1awthfaaji2XOb6YtfMmKFHj1PqMZs-4zW/s1196/Screenshot%202022-04-14%20at%2010.59.54%20AM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1020&quot; data-original-width=&quot;1196&quot; height=&quot;273&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyFop3_c5n1dd3rzP1LN2YsuIIO6CxNdII4Dm-BiptybXCZbWyMZMdDD16yHlYcD2a6R3YlDzhJ2LUDFJ_xOkiWBOUAsU0bwhoah5IjZ9NDqPT2j9uX7vXZJawih9pWzu3xDiVEg7RZmJJimdjYRFeLV1awthfaaji2XOb6YtfMmKFHj1PqMZs-4zW/w335-h273/Screenshot%202022-04-14%20at%2010.59.54%20AM.png&quot; width=&quot;335&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
</description><link>https://tandonprateek.blogspot.com/2022/04/dynamic-tree-structure-with-lwc-and-apex.html</link><author>noreply@blogger.com (Prateek Tandon)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyFop3_c5n1dd3rzP1LN2YsuIIO6CxNdII4Dm-BiptybXCZbWyMZMdDD16yHlYcD2a6R3YlDzhJ2LUDFJ_xOkiWBOUAsU0bwhoah5IjZ9NDqPT2j9uX7vXZJawih9pWzu3xDiVEg7RZmJJimdjYRFeLV1awthfaaji2XOb6YtfMmKFHj1PqMZs-4zW/s72-w335-h273-c/Screenshot%202022-04-14%20at%2010.59.54%20AM.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-6830969522318459558</guid><pubDate>Sat, 06 Jun 2020 05:39:00 +0000</pubDate><atom:updated>2020-06-05T22:42:53.140-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Lightning Message Service</category><category domain="http://www.blogger.com/atom/ns#">Lightning Web Component</category><category domain="http://www.blogger.com/atom/ns#">Ligthning</category><category domain="http://www.blogger.com/atom/ns#">LMS</category><category domain="http://www.blogger.com/atom/ns#">LWC</category><category domain="http://www.blogger.com/atom/ns#">Message Channel</category><category domain="http://www.blogger.com/atom/ns#">salesforce</category><title>Let&#39;s Communicate !!! Lightning Message Service | Message Channel | Salesforce</title><description>Salesforce introduced a new feature Lightning Message Service (LMS) in Winter 20 and is generally available in Summer 20. This feature allows developers to easily communicate between VF and Lightning. This feature provides a quick channel to which consumers can consume and get both updates and convenient tags/modules, so developers don&#39;t have to worry about CometD resources and/or complicated Javascript.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In this blog, I will share with you how to create an LMS channel and then write code in LWC and VF both to send messages.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Use Case&lt;/b&gt;: I want to display selected account record details on the VF Page, I will select the account record on the LWC component and for that account, all information will be displayed on VF Page.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Before we start writing our code, we have to create a Message Channel. As of right now, the only way to leverage this is by using Metadata API.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;How we can create Message Channel?&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Message Channel can be created using VS Code. You need to follow the below steps to create Message Channel.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;ol style=&quot;text-align: left;&quot;&gt;&lt;li&gt;Create a folder under force-app/menu/default folder and the folder name will be &lt;b&gt;&quot;messageChannels&quot;&lt;/b&gt;&lt;/li&gt;&lt;li&gt;Once you have created the folder, under that folder you need to create a file with naming convention as &lt;b&gt;&quot;SampleMessageChannel.messageChannel-meta.xml&quot;&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Once you have created the file we need to add some XML code into that file and will look something like below&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #557799;&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;LightningMessageChannel&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;xmlns=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;http://soap.sforce.com/2006/04/metadata&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;masterLabel&amp;gt;&lt;/span&gt;PassRecordId&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/masterLabel&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;isExposed&amp;gt;&lt;/span&gt;true&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/isExposed&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;description&amp;gt;&lt;/span&gt;This Lightning Message Channel sends information from LWC to VF.&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightningMessageFields&amp;gt;&lt;/span&gt;
       &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;fieldName&amp;gt;&lt;/span&gt;recordIdToSend&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/fieldName&amp;gt;&lt;/span&gt;
       &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;description&amp;gt;&lt;/span&gt;Record Id to be send&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/lightningMessageFields&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightningMessageFields&amp;gt;&lt;/span&gt;
       &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;fieldName&amp;gt;&lt;/span&gt;objectName&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/fieldName&amp;gt;&lt;/span&gt;
       &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;description&amp;gt;&lt;/span&gt;Identifies for which object we are sending the record id&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/lightningMessageFields&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/LightningMessageChannel&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Where the&amp;nbsp;&lt;b&gt;&quot;lightningMessageFields&quot; &lt;/b&gt;tag is used to create a parameter that we need to send via LMS. We can create as many fields as we want per requirement. In my case, I have created &lt;b&gt;&quot;recordIdToSend&quot; &lt;/b&gt;as a parameter which will hold Account record Id and &lt;b&gt;&quot;objectName&quot; &lt;/b&gt;will hold the object name as &#39;Account&#39;.&lt;/div&gt;&lt;div&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;4. Now, we need to add the entry for LMS in package.xml&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;types&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;members&amp;gt;&lt;/span&gt;*&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/members&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;name&amp;gt;&lt;/span&gt;LightningMessageChannel&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/name&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/types&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Let&#39;s create the LWC component and VF Page to publish and subscribe to the LMS.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;VF Page code&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;To subscribe to the LMS on the VF page we use &lt;b&gt;sforce.one&lt;/b&gt; API.&lt;/div&gt;&lt;div&gt;If you see in the below code I have subscribed the channel using &lt;b&gt;sforce.one.subscribe &lt;/b&gt;method.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;&amp;lt;!--&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @File Name          : LMS_AccountDetails.page&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @Description        : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @Author             : @tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @Group              : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @Last Modified By   : @tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @Last Modified On   : 6/6/2020, 7:52:36 AM&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  @Modification Log   : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  Ver       Date            Author      		    Modification&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;  1.0    6/6/2020   @tandonprateek     Initial Version&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;--&amp;gt;&lt;/span&gt;

&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;apex:page&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;controller=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;LMS_AccountDetailsController&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;var&lt;/span&gt; PASSRECORDID &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;{!JSENCODE($MessageChannel.PassRecordId__c)}&quot;&lt;/span&gt;;
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;var&lt;/span&gt; subscriptionToMC;
        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;if&lt;/span&gt; (&lt;span style=&quot;color: #333333;&quot;&gt;!&lt;/span&gt;subscriptionToMC) {
            subscriptionToMC &lt;span style=&quot;color: #333333;&quot;&gt;=&lt;/span&gt; sforce.one.subscribe(PASSRECORDID, onPublished, {scope&lt;span style=&quot;color: #333333;&quot;&gt;:&lt;/span&gt; &lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;APPLICATION&quot;&lt;/span&gt;});&lt;br /&gt;        }

        &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;function&lt;/span&gt; onPublished(message) {
            console.log(&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&#39;recordId on VF page ==== &#39;&lt;/span&gt; &lt;span style=&quot;color: #333333;&quot;&gt;+&lt;/span&gt; message.recordIdToSend);
            getAccountData(message.recordIdToSend);
        }
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;apex:form&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;apex:actionFunction&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;name=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;getAccountData&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;action=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;{!fetchAccountDetailRecord}&quot;&lt;/span&gt;  &lt;span style=&quot;color: #0000cc;&quot;&gt;reRender=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;accountDetailsBlock&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;apex:param&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;name=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;recordId&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;value=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&amp;lt;/apex:param&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/apex:actionFunction&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;apex:pageBlock&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;id=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;accountDetailsBlock&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;title=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;VF Page Display Account Details&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;apex:pageBlockSection&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;id=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;accountSection&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
                
                    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;apex:outputField&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;value=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;{!accDetailObject.Name}&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&amp;lt;/apex:outputField&amp;gt;&lt;/span&gt;
                    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;apex:outputField&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;value=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;{!accDetailObject.Phone}&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&amp;lt;/apex:outputField&amp;gt;&lt;/span&gt;
                
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/apex:pageBlockSection&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/apex:pageBlock&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/apex:form&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/apex:page&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Apex Class&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;
&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;/**
 * @File Name          : LMS_AccountDetailsController.cls
 * @Description        : 
 * @Author             : @tandonprateek
 * @Group              : 
 * @Last Modified By   : @tandonprateek
 * @Last Modified On   : 6/6/2020, 7:53:48 AM
 * @Modification Log   : 
 * Ver       Date            Author      		    Modification
 * 1.0    6/6/2020   @tandonprateek     Initial Version
**/

public with sharing class LMS_AccountDetailsController {

    public Account accDetailObject {get;set;}

    
    /**
    * @description 
    * @author @tandonprateek | 6/6/2020 
    * @return Pagereference 
    **/
    public Pagereference fetchAccountDetailRecord(){
        String accId = Apexpages.currentPage().getParameters().get(&#39;recordId&#39;);
        accDetailObject = [Select Id, Name, Phone from Account where Id =: accId];
        return null;
    }
}
&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;LWC Component code&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;span style=&quot;color: #888888;&quot;&gt;&amp;lt;!--&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;   @File Name          : accountInfoComponent.html&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;   @Description        : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;   @Author             : @tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;   @Group              : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;   @Last Modified By   : @tandonprateek&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;   @Last Modified On   : 6/6/2020, 7:51:35 AM&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;   @Modification Log   : &lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;   Ver       Date            Author      		    Modification&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;   1.0    6/6/2020   @tandonprateek     Initial Version&lt;/span&gt;
&lt;span style=&quot;color: #888888;&quot;&gt;   --&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-page-header&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-grid&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
         &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-col slds-has-flexi-truncate&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-text-title_caps slds-line-height_reset&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;LWC Component Account Info&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;h1&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-page-header__title slds-m-right_small slds-align-middle slds-truncate&quot;&lt;/span&gt;  &lt;span style=&quot;color: #0000cc;&quot;&gt;title=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;AccountInfo&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;Acount Info&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
         &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-button&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Get All Accounts&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onclick=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleClick}&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-button&amp;gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-card&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;title=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Account Result Data&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;icon-name=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;custom:custom3&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-m-around_medium&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
         &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;template&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;for:each=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{finalData}&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;for:item=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;acc&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
               &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;li&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;key=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{acc.Id}&lt;/span&gt; &lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
                  &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;a&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;hrefv=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;javascript:void(0);&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;data-record-id=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{acc.Id}&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onclick=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleClickonAccountName}&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;{acc.Name}&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
               &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
         &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
      &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-card&amp;gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To use LMS in LWC we need to first import the methods from lightning/MessageChannel library and import the message channel, in my case, I need to add the below code to my LWC js file.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;import { publish,createMessageContext,releaseMessageContext, subscribe, unsubscribe } from &#39;lightning/messageService&#39;;
import PassRecordId from &quot;@salesforce/messageChannel/PassRecordId__c&quot;;
&lt;/pre&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Below is my LWC js file&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;/**
 * @File Name          : accountInfoComponent.js
 * @Description        : 
 * @Author             : @tandonprateek
 * @Group              : 
 * @Last Modified By   : @tandonprateek
 * @Last Modified On   : 6/6/2020, 7:51:50 AM
 * @Modification Log   : 
 * Ver       Date            Author             Modification
 * 1.0    6/6/2020   @tandonprateek     Initial Version
**/
import { LightningElement, track } from &quot;lwc&quot;;
import { searchAccountByName, searchAccountById, searchAccountsByIds, fetchAccounts, fetchAllAccounts } from &quot;c/accountService&quot;;
import { publish,createMessageContext,releaseMessageContext, subscribe, unsubscribe } from &#39;lightning/messageService&#39;;
import PassRecordId from &quot;@salesforce/messageChannel/PassRecordId__c&quot;;

export default class AccountInfoComponent extends LightningElement {
    searchKey = &#39;&#39;;
    searchKeyText = &#39;&#39;;
    data = [];
    context = createMessageContext();

    handleClick() {
        fetchAllAccounts()
            .then(result =&amp;gt; {
                this.data = result;
                console.log(result);
            })
            .catch(error =&amp;gt; {
                console.log(error.message);
            });
    }

    get finalData(){
        return this.data;
    }

    handleClickonAccountName(event){
        //let recordId = event.currentTarget.getAttribute(&#39;key&#39;);
        //let recordId = event.target.value;
        let recordId = event.target.dataset.recordId;
        console.log(&#39;recordId ==== &#39; + recordId);
        const payload = {
            recordIdToSend: recordId,
            objectName: &#39;Account&#39;
        };

        publish(this.context, PassRecordId, payload);
    }

}
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here I have used Service Components to get the account records, you can refer to my &lt;a href=&quot;https://tandonprateek.blogspot.com/2020/05/lightning-web-component-what-are.html&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;previous blog &lt;/a&gt;about Service Component in LWC.&lt;/div&gt;&lt;div&gt;Now, to publish the LMS I need to call the&amp;nbsp;&lt;b&gt;publish &lt;/b&gt;method to call the LMS channel and pass the payload to the channel.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Below is the demo:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.blogger.com/video.g?token=AD6v5dxhucX-QOxZu_2LohDZe5yHt9zUj_kG2T0u08aqgxNBDS8JskoTXsZE2YAIvjNjMLLb7xwOK-lXQWyJKoCDog&#39; class=&#39;b-hbp-video b-uploaded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In summary, LMS provides us a very easy and quick way to move complex data across the DOM between LWC and VF Page, allowing for better interoperability.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;References:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;https://releasenotes.docs.salesforce.com/en-us/winter20/release-notes/rn_lc_message_channel.htm&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;https://newstechnologystuff.com/2020/03/22/lightning-message-service-quick-demo/&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;</description><link>https://tandonprateek.blogspot.com/2020/06/lets-communicate-lightning-message.html</link><author>noreply@blogger.com (Prateek Tandon)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-6394004322561081059</guid><pubDate>Sat, 30 May 2020 18:32:00 +0000</pubDate><atom:updated>2020-05-30T11:41:11.370-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Extensions</category><category domain="http://www.blogger.com/atom/ns#">plugins</category><category domain="http://www.blogger.com/atom/ns#">salesforce</category><category domain="http://www.blogger.com/atom/ns#">VS Code</category><category domain="http://www.blogger.com/atom/ns#">VSCode</category><title>Useful VS Code Extensions</title><description>&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;I, like many others, are fans of extensions which helps in boosting productivity while coding.&amp;nbsp; I am constantly looking for such plugins, settings, themes, and productive tips to enhance my coding experience.&lt;/font&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;Since I started using VS Code for Salesforce development I was looking for some cool plugins which increase my productivity and also help me to gain my coding experience.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;I am guessing most people are already aware of some extensions or maybe using on a daily basis because these extensions are useable.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;Therefore, I decided to create a list with some of my favorite or maybe useful VS Code extensions. So without further ado lets list out the extensions.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;1. Salesforce Extension Pack&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;This&amp;nbsp;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=salesforce.salesforcedx-vscode&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;extension&lt;/a&gt;&amp;nbsp;is very important if you are doing Salesforce development. This tool will provide features for working with development orgs (scratch orgs, sandboxes and DE orgs), Apex, Aura components, Lightning Web Components, Visualforce.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;2. Salesforce Documenter&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;This&amp;nbsp;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=HugoOM.sfdx-autoheader&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;extension&lt;/a&gt;&amp;nbsp;helps in facilitating proper and structured code documenting for Salesforce related files. This tool is very useful for the developers as it makes the code more readable and easy to understand by automating tasks such as adding File headers as well as Method headers. Also, this tool is very useful for lazy 😴 developers like me who usually add one-liners as method headers.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;After installing this extension to VS Code, go to any Apex class and select method and right-click you will see the option as &#39;&lt;b&gt;Generate Apex Method Header&lt;/b&gt;&#39;, click on it and you will get the header added automatically on the method.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBBYJjRAdOdk6-pdzenw7c7IlXHQn0AQWbBPBjzcMqguolKCZwmR7gBAA69U3tM2i8__Yz-kqChYj9ClG6Jhu9HF7bsfP8G5oWzOUrGEooEk7118erWmC4VSDRnmfleJBc9tf4iO7IQk0/&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;892&quot; data-original-width=&quot;2010&quot; height=&quot;284&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBBYJjRAdOdk6-pdzenw7c7IlXHQn0AQWbBPBjzcMqguolKCZwmR7gBAA69U3tM2i8__Yz-kqChYj9ClG6Jhu9HF7bsfP8G5oWzOUrGEooEk7118erWmC4VSDRnmfleJBc9tf4iO7IQk0/w640-h284/Screenshot+2020-05-30+at+11.32.19+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;Also, if you see there is another option available as &#39;&lt;b&gt;Insert File Header&lt;/b&gt;&#39;, this will add the headers on the Apex class.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;3. Salesforce Package.xml Generator&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;This &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=VignaeshRamA.sfdx-package-xml-generator&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;extension&lt;/a&gt; provides a User Interface to choose metadata components for the Package.xml file for development against sandboxes or DE orgs. This is similar to the Eclipse Force.com IDE Add/Remove Metadata Components option.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;4. Local History&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;A visual code extension for maintaining the&amp;nbsp;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=xyz.local-history&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;local history&lt;/a&gt;&amp;nbsp;of files. This extension is a savior for me many times.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;This extension&amp;nbsp;will help you out when you change a file or delete the file by accident 😈. Every time you make changes to a file, a copy of the old content of that file is stored in local history. With the help of this tool, at any time you can compare the existing code with any older version of the file from history.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;5. Highlight Matching Tag&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;As the name suggests this&amp;nbsp;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=vincaslt.highlight-matching-tag&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;extension&lt;/a&gt;&amp;nbsp;highlights the matching closing tags, be it on the same line or far down the editor. This is especially useful when you have nested tags and several lines of codes to read.&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigkxGsqMohK_awEHbfYobOgksIxfqMafR1iJFMO1cYOrs6oDesgf8mqeqSDK2WhyiK0VIAotiUfdzsHLLochtfg1OCvzHTt_HgZtmJU51XNjy68es0PeNID3MwfO1GR1NvZuBL410qUlY/&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;230&quot; data-original-width=&quot;1254&quot; height=&quot;118&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigkxGsqMohK_awEHbfYobOgksIxfqMafR1iJFMO1cYOrs6oDesgf8mqeqSDK2WhyiK0VIAotiUfdzsHLLochtfg1OCvzHTt_HgZtmJU51XNjy68es0PeNID3MwfO1GR1NvZuBL410qUlY/w640-h118/Screenshot+2020-05-30+at+11.08.12+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;In the above image as you can see this tool highlighted the start and end &#39;div&#39; tag.&amp;nbsp;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;6. Indented Block Highlighting&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;This one is my most&amp;nbsp;&lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=byi8220.indented-block-highlighting&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;favorite extension&lt;/a&gt;&amp;nbsp;as it exactly does the same thing as the name suggests. This tool highlights the indented block which you are working with. In my case, it highlights the block within if&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiunZZoGHeNJR_Zf_gFaJcpLZo1M_i00pYUOpudJwBSxpIZqEiqmrXJeQSPr9kAxeRWNbUbMWuAA1VjMK-lZcHnZygP4Ou00xmIGnbNaGI-wQFdxI9hzPWjpKKkraoF5jY71srH3Z6XHgc/&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1164&quot; data-original-width=&quot;2092&quot; height=&quot;357&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiunZZoGHeNJR_Zf_gFaJcpLZo1M_i00pYUOpudJwBSxpIZqEiqmrXJeQSPr9kAxeRWNbUbMWuAA1VjMK-lZcHnZygP4Ou00xmIGnbNaGI-wQFdxI9hzPWjpKKkraoF5jY71srH3Z6XHgc/w640-h357/Screenshot+2020-05-30+at+11.22.51+PM.png&quot; width=&quot;640&quot; /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;So this is my list of VS Code extensions that I use on a daily basis. Some of the extensions are not that popular but they got the job done.&lt;/font&gt;&lt;/div&gt;</description><link>https://tandonprateek.blogspot.com/2020/05/useful-vs-code-extensions.html</link><author>noreply@blogger.com (Prateek Tandon)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBBYJjRAdOdk6-pdzenw7c7IlXHQn0AQWbBPBjzcMqguolKCZwmR7gBAA69U3tM2i8__Yz-kqChYj9ClG6Jhu9HF7bsfP8G5oWzOUrGEooEk7118erWmC4VSDRnmfleJBc9tf4iO7IQk0/s72-w640-h284-c/Screenshot+2020-05-30+at+11.32.19+PM.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-8463743768823778228</guid><pubDate>Sun, 24 May 2020 18:23:00 +0000</pubDate><atom:updated>2020-05-26T22:35:22.038-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Lightning Web Component</category><category domain="http://www.blogger.com/atom/ns#">Ligthning</category><category domain="http://www.blogger.com/atom/ns#">LWC</category><category domain="http://www.blogger.com/atom/ns#">salesforce</category><category domain="http://www.blogger.com/atom/ns#">Service Component</category><title>Lightning Web Component : What are Service Components &amp; How are they Useful?</title><description>&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;As we keep working on complex LWC applications,&amp;nbsp;&lt;span style=&quot;background-color: white; color: #4a4a4a; font-size: 16px;&quot;&gt;it’s inevitable that complexity will increase. With increased complexity in code, we will need to write a modular reusable code. In this blog, I will try to explain how we can create a reusable LWC code using Service Components.&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;span style=&quot;background-color: white; color: #4a4a4a; font-size: 16px;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white; color: #4a4a4a; font-size: 16px;&quot;&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;Let&#39;s try to define What is Service Components?&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white; color: #4a4a4a; font-size: 16px;&quot;&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white; font-size: 16px;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;A service component is a component that provides a set of functionalities in a single component. Ideally, the service should be specialized, generic, and reusable. Also, this component does not have a markup, i.e. this is not visible by default.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white; font-size: 16px;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;This helps in reducing code duplication and simplifies the component&#39;s code. This, in turn, makes the code more robust and easier to maintain.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white; font-size: 16px;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;How we can Create a Service Component?&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;I have taken an Account object for my example and I will be creating a service component for my Account object.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;AccountService.cls as Apex Class:&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/font&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;public with sharing class AccountService {
    
    public AccountService() {

    }

    @AuraEnabled
    public static List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Account&amp;gt;&lt;/span&gt; searchAccountByName(String accountName) {
        List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Account&amp;gt;&lt;/span&gt; accounts = [SELECT Id, Name FROM Account WHERE Name=:accountName];
        if (accounts.size() &amp;gt; 0) {
            return accounts;
        }
        return null;
    }

    @AuraEnabled
    public static List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Account&amp;gt;&lt;/span&gt; fetchAccountById(String accountId) {
        List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Account&amp;gt;&lt;/span&gt; accounts = [SELECT Id, Name FROM Account WHERE Id=:accountId];
        if (accounts.size() &amp;gt; 0) {
            return accounts;
        }
        return null;
    }

    @AuraEnabled
    public static List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Account&amp;gt;&lt;/span&gt; fetchAccountsByIds(List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Id&amp;gt;&lt;/span&gt; accountIds) {
        List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Account&amp;gt;&lt;/span&gt; accounts = [SELECT Id, Name FROM Account WHERE Id in: accountIds];
        if (accounts.size() &amp;gt; 0) {
            return accounts;
        }
        return null;
    }

    @AuraEnabled
    public static List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Account&amp;gt;&lt;/span&gt; searchAccounts(String accountName) {
        String query = &#39;Select Id, Name from Account where Name like &#39; + &#39;\&#39;%&#39; + accountName + &#39;%\&#39;&#39;;
        List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Account&amp;gt;&lt;/span&gt; accounts = Database.query(query);
        if (accounts.size() &amp;gt; 0) {
            return accounts;
        }
        return null;
    }

    @AuraEnabled
    public static List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Account&amp;gt;&lt;/span&gt; fetchAllAccounts(List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Id&amp;gt;&lt;/span&gt; accountIds) {
        List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;Account&amp;gt;&lt;/span&gt; accounts = [SELECT Id, Name FROM Account LIMIT 10];
        if (accounts.size() &amp;gt; 0) {
            return accounts;
        }
        return null;
    }
}
&lt;/font&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;accountService as Service Component:&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/font&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;import getAccountByName from &quot;@salesforce/apex/AccountService.searchAccountByName&quot;;
import getAccountById from &quot;@salesforce/apex/AccountService.fetchAccountById&quot;;
import getAccountsByIds from &quot;@salesforce/apex/AccountService.fetchAccountsByIds&quot;;
import getAccounts from &quot;@salesforce/apex/AccountService.searchAccounts&quot;;
import getAllAccounts from &quot;@salesforce/apex/AccountService.fetchAllAccounts&quot;;

const searchAccountByName = async accountName =&amp;gt; {
   const response = await getAccountByName({ accountName: accountName });
   return response;
};

const searchAccountById = async accountId =&amp;gt; {
    const response = await getAccountById({ accountId: accountId });
    return response;
};

const searchAccountsByIds = async accountIds =&amp;gt; {
    const response = await getAccountsByIds({ accountIds: accountIds });
    return response;
};

const fetchAccounts = async accountName =&amp;gt; {
    const response = await getAccounts({ accountName: accountName });
    return response;
 };

const fetchAllAccounts = () =&amp;gt; {
   return new Promise(resolve =&amp;gt; {
    getAllAccounts()
         .then(data =&amp;gt; {
            resolve(data);
         })
         .catch(error =&amp;gt; {
            resolve(error);
         });
   });
};

export { searchAccountByName, searchAccountById, searchAccountsByIds, fetchAccounts, fetchAllAccounts };
&lt;/font&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;In the above component, I have exposed the below services &lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;ul style=&quot;text-align: left;&quot;&gt;&lt;li&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;b&gt;searchAccountByName&lt;/b&gt;: it accepts the search key as accountName and will return the account record with the exact account name&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;b&gt;searchAccountById&lt;/b&gt;: it accepts the search key as accountId and will return the account with the exact account id&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;b&gt;searchAccountsByIds&lt;/b&gt;: it accepts the set of account ids and will return the list of account&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;b&gt;fetchAccounts&lt;/b&gt;: it accepts the search key as accountName and will return the list of Account records which contains name as search keyword.&lt;/font&gt;&lt;/li&gt;&lt;li&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;b&gt;fetchAllAccounts&lt;/b&gt;: this returns the list of accounts.&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;You will also notice that I have followed the &lt;b&gt;Singleton&lt;/b&gt; pattern to develop this component i.e. this component has only one instance.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;Now to use the above services, I have created one component which will consume these services.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;b&gt;accountInfo as LWC Component&lt;/b&gt;:&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;accountInfoComponent.html&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/font&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-button&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Get All Accounts&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onclick=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleClick}&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-button&amp;gt;
      
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-layout&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;vertical-align=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;end&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-m-bottom_small&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-layout-item&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;flexibility=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;grow&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
                &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-input&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;type=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;search&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onchange=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleKeyChange}&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Search By Exact Name&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;value=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{searchKey}&lt;/span&gt; &lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-input&amp;gt;
            &lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-layout-item&amp;gt;
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-layout-item&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-p-left_xx-small&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
                &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-button&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Search By Exact Name&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onclick=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleSearchAccountByName}&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-button&amp;gt;
            &lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-layout-item&amp;gt;
        &lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-layout&amp;gt;

        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-layout&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;vertical-align=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;end&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-m-bottom_small&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-layout-item&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;flexibility=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;grow&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
                &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-input&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;type=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;search&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onchange =&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleKeyTextChange}&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Filter By Name&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;value=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{searchKeyText}&lt;/span&gt; &lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-input&amp;gt;
            &lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-layout-item&amp;gt;
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-layout-item&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-p-left_xx-small&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
                &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-button&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;label=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Filter By Name&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;onclick=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{handleSearchAccountsByName}&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-button&amp;gt;
            &lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-layout-item&amp;gt;
        &lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-layout&amp;gt;

        
            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-card&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;title=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Account Result Data&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;icon-name=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;custom:custom3&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
                &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-m-around_medium&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
                        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
                            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;template&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;for:each=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{finalData}&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;for:item=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;acc&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
                                &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;li&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;key=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;{acc.Id}&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;{acc.Name}
                                    
                                &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
                            &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
                        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
                &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
            &lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-card&amp;gt;

        
      &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/font&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;accountInfoComponent.js&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;import { LightningElement, track } from &quot;lwc&quot;;
import { searchAccountByName, searchAccountById, searchAccountsByIds, fetchAccounts, fetchAllAccounts } from &quot;c/accountService&quot;;


export default class AccountInfoComponent extends LightningElement {
    searchKey = &#39;&#39;;
    searchKeyText = &#39;&#39;;
    data = [];


    handleKeyChange(event) {
        this.searchKey = event.target.value;
    }

    //get all the accounts
    handleClick() {
        fetchAllAccounts()
            .then(result =&amp;gt; {
                this.data = result;
                console.log(result);
            })
            .catch(error =&amp;gt; {
                console.log(error.message);
            });
    }

    //get Account by Name
    handleSearchAccountByName() {
        this.fetchAccountByName(this.searchKey);
    }

    async fetchAccountByName(accountName) {
        try {
            let account = await searchAccountByName(accountName);
            this.data = account;
        } catch (err) {
            console.log(err);
        }
    }

    //get Account by Id
    handleSearchAccountById() {
        this.fetchAccountById(this.accountId);
    }

    async fetchAccountById(accountId) {
        try {
            let account = await searchAccountById(accountId);
            this.data = account;
        } catch (err) {
            console.log(err);
        }
    }

    //get Accounts by Ids
    handleSearchAccountsByIds() {
        this.fetchAccountsByIds(this.accountIds);
    }

    async fetchAccountsByIds(accountIds) {
        try {
            let accounts = await searchAccountsByIds(accountIds);
            this.data = accounts;
        } catch (err) {
            console.log(err);
        }
    }

    handleKeyTextChange(event){
        this.searchKeyText = event.target.value;
    }

    //get accounts by name with a search text on name
    handleSearchAccountsByName() {
        this.fetchAccountsByName(this.searchKeyText);
    }

    async fetchAccountsByName(accountName) {
        try {
            let accounts = await fetchAccounts(accountName);
            this.data = accounts;
        } catch (err) {
            console.log(err);
        }
    }

    get finalData(){
        console.log(&#39;wwww &#39; + JSON.stringify(this.data))    ;
        return this.data;
    }

}
&lt;/pre&gt;&lt;/div&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;b&gt;accountInfoComponent.js-met.xml&lt;/b&gt;:&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;!--HTML generated using hilite.me--&gt;&lt;/font&gt;&lt;div style=&quot;background: rgb(255, 255, 255); border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;&lt;pre style=&quot;line-height: 125%; margin: 0px;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;span style=&quot;color: #557799;&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;LightningComponentBundle&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;xmlns=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;http://soap.sforce.com/2006/04/metadata&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;apiVersion&amp;gt;&lt;/span&gt;48.0&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/apiVersion&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;isExposed&amp;gt;&lt;/span&gt;true&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/isExposed&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;targets&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;target&amp;gt;&lt;/span&gt;lightning__AppPage&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/target&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/targets&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/LightningComponentBundle&amp;gt;&lt;/span&gt;
&lt;/font&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&lt;font face=&quot;times&quot; size=&quot;4&quot;&gt;References:&amp;nbsp;&lt;a href=&quot;https://developer.salesforce.com/blogs/2019/05/lightning-web-components-service-components.html&quot;&gt;https://developer.salesforce.com/blogs/2019/05/lightning-web-components-service-components.html&lt;/a&gt;&lt;/font&gt;&lt;/div&gt;</description><link>https://tandonprateek.blogspot.com/2020/05/lightning-web-component-what-are.html</link><author>noreply@blogger.com (Prateek Tandon)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-3176515575570892585</guid><pubDate>Wed, 20 May 2020 12:48:00 +0000</pubDate><atom:updated>2020-05-24T05:51:22.154-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">CDC</category><category domain="http://www.blogger.com/atom/ns#">Change Data Capture</category><category domain="http://www.blogger.com/atom/ns#">event message</category><category domain="http://www.blogger.com/atom/ns#">external source</category><category domain="http://www.blogger.com/atom/ns#">external system</category><category domain="http://www.blogger.com/atom/ns#">mule</category><category domain="http://www.blogger.com/atom/ns#">mulesoft</category><category domain="http://www.blogger.com/atom/ns#">salesforce</category><category domain="http://www.blogger.com/atom/ns#">Subscription Channel</category><title>Part II : Change Data Capture ... Learn How To Subscribe Change Data Capture to External Source</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In my previous blog, I have discussed Salesforce Change Data Capture and how this feature helps to publish change events that represent changes to records. I have taken an example to display change event records or messages on the Lightning Web Component using Platform Events. If your interested to have a look at my previous blog, please feel free to visit on below link:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://tandonprateek.blogspot.com/2020/05/understanding-change-data-capture-using.html&quot; target=&quot;_blank&quot;&gt;Understanding Change Data Capture using Asynchronous Apex Triggers and Handling Platform Event in Lightning Web Components&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
In this blog, we will discuss how we can subscribe to Change Data Capture events and get the changed records that we can easily import to the external source.&lt;br /&gt;
&lt;br /&gt;
To explain this I will be taking MuleSoft as a middleware tool that receives the message from the Subscribe Channel from salesforce and convert the message to the required format of another tool, so I will be passing change event records to MuleSoft using Subscription Channel and I will be fetching all the changed Case records in MuleSoft.&lt;br /&gt;
&lt;br /&gt;
First, we need to set up the Change Data Capture and select the object for which we need to receive notifications for record changes. For my example, I will be selecting the Case object.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifcR3BRmchMU7mnt1GnVgn_mZoLg0hdgqsRjt4KEhK2xL28KVbFxEHCMxm-_kUlPRNa3vzuQgZ1ShxO8MBTzuSem4MWmqBxU5FFmP6XhXJXNESuGJMNQ1Hb4MXNgAs8qGgbSKiuve7PhU/s1600/Screenshot+2020-05-18+at+12.32.57+PM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;899&quot; data-original-width=&quot;1600&quot; height=&quot;223&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifcR3BRmchMU7mnt1GnVgn_mZoLg0hdgqsRjt4KEhK2xL28KVbFxEHCMxm-_kUlPRNa3vzuQgZ1ShxO8MBTzuSem4MWmqBxU5FFmP6XhXJXNESuGJMNQ1Hb4MXNgAs8qGgbSKiuve7PhU/s400/Screenshot+2020-05-18+at+12.32.57+PM.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Once you have selected the object and saved it, salesforce will create a Subscription Channel with a name as CaseChangeEvent. To understand more on Subscription Channel, please click &lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_subscribe_channels.htm&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. Also, in the previous blog, I have discussed little regarding Subscription Channel and naming conventions.&lt;br /&gt;
&lt;br /&gt;
We are all done from the Salesforce side, now we need to move to the Mule platform and see how we can subscribe to the streaming channel provided by Salesforce.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
So, in MuleSoft we will be selecting Salesforce connector and we will be using the Subscription Channel component, to receive events from Salesforce.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
We will do the required Connector Configuration and provide the Streaming channel name. In this example, I have used the &#39;Basic Username and Password&#39; connection and the channel name will be &#39;/data/CaseChangeEvent&#39;.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Below will be the MuleSoft flow:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPvonpgIwtOTB8qyuFFKf-lbzghr_25DgP_g_EV5mljPA3_EU9tYj99ISYsj7h0lGkWtDvKCzmvJs-cbg9hijSZ-JE2wcNl_vGhsx4P0b-6xRCMMNm2c8pkue0EFM8HFbUrn0LIB4HC5U/s1600/Screenshot+2020-05-20+at+3.03.07+PM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;552&quot; data-original-width=&quot;776&quot; height=&quot;227&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPvonpgIwtOTB8qyuFFKf-lbzghr_25DgP_g_EV5mljPA3_EU9tYj99ISYsj7h0lGkWtDvKCzmvJs-cbg9hijSZ-JE2wcNl_vGhsx4P0b-6xRCMMNm2c8pkue0EFM8HFbUrn0LIB4HC5U/s320/Screenshot+2020-05-20+at+3.03.07+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Configuration for Subscriber Channel component and Salesforce Connector:&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOLiMys2buGF2LBFbfmQVS0ngAf_Rcvke4FgjJsb4vMQq7sn70PSzB9kcEzvu6kiAJQAHPBTlKzw7WkIIFP9L0faQhnJYEd5DBAsGZmujW64sgMNdLuL1YUcyKG-mro_k9T4xDmMvv000/s1600/Screenshot+2020-05-20+at+3.03.15+PM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;540&quot; data-original-width=&quot;326&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjOLiMys2buGF2LBFbfmQVS0ngAf_Rcvke4FgjJsb4vMQq7sn70PSzB9kcEzvu6kiAJQAHPBTlKzw7WkIIFP9L0faQhnJYEd5DBAsGZmujW64sgMNdLuL1YUcyKG-mro_k9T4xDmMvv000/s320/Screenshot+2020-05-20+at+3.03.15+PM.png&quot; width=&quot;193&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTETyZIdXjUGmirf6FqfcyvTwIvIv4mdpOQ7s_TxpdaY1hriCSqLGdGBsrHhxBXnn2UrtYQqTeznUPcf3I9_FpceF5EfIcvcUBbhd1YOjo_I8KD2MXhnFQ-OITNgaddWcJ4ZzLjjrw12Q/s1600/Screenshot+2020-05-20+at+3.17.08+PM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;1518&quot; data-original-width=&quot;1444&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTETyZIdXjUGmirf6FqfcyvTwIvIv4mdpOQ7s_TxpdaY1hriCSqLGdGBsrHhxBXnn2UrtYQqTeznUPcf3I9_FpceF5EfIcvcUBbhd1YOjo_I8KD2MXhnFQ-OITNgaddWcJ4ZzLjjrw12Q/s320/Screenshot+2020-05-20+at+3.17.08+PM.png&quot; width=&quot;304&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLv-RClfkDLJo_sDFi5-C9IkbonW4RpeTPhf9sjL4z_9zmGYxff7mjmUwej5juA5J_o9Ib9kRkdYcqaUX0M9TR1-fTJ6ShyphenhyphenHNFVjebZVfTxd-DYB7V9e-yqdc78pTJ6XC3zvn1zKQJIlE/s1600/Screenshot+2020-05-20+at+3.17.18+PM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;704&quot; data-original-width=&quot;1598&quot; height=&quot;140&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLv-RClfkDLJo_sDFi5-C9IkbonW4RpeTPhf9sjL4z_9zmGYxff7mjmUwej5juA5J_o9Ib9kRkdYcqaUX0M9TR1-fTJ6ShyphenhyphenHNFVjebZVfTxd-DYB7V9e-yqdc78pTJ6XC3zvn1zKQJIlE/s320/Screenshot+2020-05-20+at+3.17.18+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Now to read the response from the subscribed channel we will be using the Transform Message component and Logger component to generate the log for the payload which we have received from the channel.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBjJwqX6kgt8EARkLhSzS5xF47uikVAbw5Zun82yJhfw3WZhqIi6-JkXgvFEjpdv0S4NtA6IgENhXwyK0bVlu39gWvk3YHt-T2Xs1oVdIXn6lESWr1to07I7pGMgod_uzRePoQzqUjW2w/s1600/Screenshot+2020-05-20+at+3.03.39+PM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;414&quot; data-original-width=&quot;253&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBjJwqX6kgt8EARkLhSzS5xF47uikVAbw5Zun82yJhfw3WZhqIi6-JkXgvFEjpdv0S4NtA6IgENhXwyK0bVlu39gWvk3YHt-T2Xs1oVdIXn6lESWr1to07I7pGMgod_uzRePoQzqUjW2w/s320/Screenshot+2020-05-20+at+3.03.39+PM.png&quot; width=&quot;194&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIixzarE8688fdT4tP8X5_Css1EvcKvThU7dPrpYtFvXDC3FS0x5XVJRH6mR2cMeO5iE2sUNcr83HodLq1eK8vSTPjDm-uybQ2Su_LuvOr5-Fu-Zlqvs0Cyx8hHGakFC8wbsTUJSGnq34/s1600/Screenshot+2020-05-20+at+3.20.11+PM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;591&quot; data-original-width=&quot;1600&quot; height=&quot;118&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIixzarE8688fdT4tP8X5_Css1EvcKvThU7dPrpYtFvXDC3FS0x5XVJRH6mR2cMeO5iE2sUNcr83HodLq1eK8vSTPjDm-uybQ2Su_LuvOr5-Fu-Zlqvs0Cyx8hHGakFC8wbsTUJSGnq34/s320/Screenshot+2020-05-20+at+3.20.11+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Here, you can transform the payload into JSON object or Array of an object as per your convenience or whatever format is supported by another tool where you want to import the data.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfgIJDqwseBQQNM1hnhAfVKhvBImUHTjlrF5iFgmJqtb8R9piNvjhaXYU_R-SUT0iScYEqlNrhAImc5Ma6fVTIeRaHYWxzNKZtz09aWK4XBqImugr34_WpIMZUD-3LQfTtlykv-0VTP4Q/s1600/Screenshot+2020-05-20+at+3.03.44+PM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;446&quot; data-original-width=&quot;238&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfgIJDqwseBQQNM1hnhAfVKhvBImUHTjlrF5iFgmJqtb8R9piNvjhaXYU_R-SUT0iScYEqlNrhAImc5Ma6fVTIeRaHYWxzNKZtz09aWK4XBqImugr34_WpIMZUD-3LQfTtlykv-0VTP4Q/s320/Screenshot+2020-05-20+at+3.03.44+PM.png&quot; width=&quot;170&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha9hk0UjcMm2ITaR9yHSovf18ZzXaYvBrs9Ga6ve1UdGxQ0_6aNhZ4ogjt5JnyXii_tPwu-bA_ine6JDkX8RuTtMFUaNLPKQPqyRztDIKYCuTsIP3TA2L62Lgb1q_sONx4tEG-sI0QYAw/s1600/Screenshot+2020-05-20+at+3.20.20+PM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;714&quot; data-original-width=&quot;1600&quot; height=&quot;142&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEha9hk0UjcMm2ITaR9yHSovf18ZzXaYvBrs9Ga6ve1UdGxQ0_6aNhZ4ogjt5JnyXii_tPwu-bA_ine6JDkX8RuTtMFUaNLPKQPqyRztDIKYCuTsIP3TA2L62Lgb1q_sONx4tEG-sI0QYAw/s320/Screenshot+2020-05-20+at+3.20.20+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Finally, its time to see the payload which we have got in the logger.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaW6q1xZ6LEuEj23LYGD3aboJJUuX2tCjq8nwQEnAXH6oHCyGK6uXqSm0r_yYhhdBZLcVBmJeixSpQZ4O7ZY7nyPIh4p4gijwzlNnDnpHPo7rJr6HzQdTX_NAwSvrnwBCbeSL7Htyxnbw/s1600/Screenshot+2020-05-20+at+3.22.33+PM.png&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;832&quot; data-original-width=&quot;1250&quot; height=&quot;212&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaW6q1xZ6LEuEj23LYGD3aboJJUuX2tCjq8nwQEnAXH6oHCyGK6uXqSm0r_yYhhdBZLcVBmJeixSpQZ4O7ZY7nyPIh4p4gijwzlNnDnpHPo7rJr6HzQdTX_NAwSvrnwBCbeSL7Htyxnbw/s320/Screenshot+2020-05-20+at+3.22.33+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
If you see the payload carefully which we have received it gives the complete information about the record that is changed in salesforce. Please refer to the change event message structure.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;/div&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;{
  &quot;data&quot;: {
    &quot;schema&quot;: &quot;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;schema&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;_ID&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;&quot;, 
    &quot;payload&quot;: {
      &quot;ChangeEventHeader&quot;: {
         &quot;entityName&quot; : &quot;...&quot;,
         &quot;recordIds&quot; : &quot;...&quot;,
         &quot;changeType&quot; : &quot;...&quot;,
         &quot;changedFields&quot;: [...],
         &quot;changeOrigin&quot; : &quot;...&quot;,
         &quot;transactionKey&quot; : &quot;...&quot;,
         &quot;sequenceNumber&quot; : &quot;...&quot;,
         &quot;commitTimestamp&quot; : &quot;...&quot;,
         &quot;commitUser&quot; : &quot;...&quot;,
         &quot;commitNumber&quot; : &quot;...&quot;
      }, 
     &quot;field1&quot;:&quot;...&quot;,
     &quot;field2&quot;:&quot;...&quot;,
     . . .
    }, 
    &quot;event&quot;: {
      &quot;replayId&quot;: &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;replayID&amp;gt;&lt;/span&gt;
    }
  }, 
  &quot;channel&quot;: &quot;/data/&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;channel&amp;gt;&lt;/span&gt;&quot;
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Please check out the descriptions of the fields which change event message contains from the below link:&lt;br /&gt;
&lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_message_structure.htm&quot; target=&quot;_blank&quot;&gt;Change Event Message Structure&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
So instead of doing periodic exports or imports of data or repeated API, we can easily make use of Change Data Capture to update in the external system.&amp;nbsp;&lt;span style=&quot;background-color: white; color: #333333;&quot;&gt;&lt;span style=&quot;font-family: Times, Times New Roman, serif;&quot;&gt;Capturing changes with Change Data Capture event notifications ensures that your external data can be updated in real-time and stays fresh.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;background-color: white; clear: both; color: #333333;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;I hope this will help to understand how we can subscribe to the change events from Salesforce using Change Data Capture to External Source.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;background-color: white; clear: both; color: #333333;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;background-color: white; clear: both; color: #333333;&quot;&gt;
&lt;span style=&quot;font-family: times, times new roman, serif;&quot;&gt;References:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;background-color: white; clear: both; color: #333333;&quot;&gt;
&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: times, times new roman, serif;&quot;&gt;&lt;a href=&quot;https://docs.mulesoft.com/mule-runtime/3.9/salesforce-connector#streaming&quot; target=&quot;_blank&quot;&gt;MuleSoft Learning and Documentation&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: times, times new roman, serif;&quot;&gt;&lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_intro.htm&quot; target=&quot;_blank&quot;&gt;Change Data Capture&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;background-color: white; clear: both; color: #333333;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;background-color: white; clear: both; color: #333333;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;Looking forward to everyone&#39;s suggestions and comments!!!&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://tandonprateek.blogspot.com/2020/05/continued-change-data-capture-learn-how.html</link><author>noreply@blogger.com (Prateek Tandon)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifcR3BRmchMU7mnt1GnVgn_mZoLg0hdgqsRjt4KEhK2xL28KVbFxEHCMxm-_kUlPRNa3vzuQgZ1ShxO8MBTzuSem4MWmqBxU5FFmP6XhXJXNESuGJMNQ1Hb4MXNgAs8qGgbSKiuve7PhU/s72-c/Screenshot+2020-05-18+at+12.32.57+PM.png" height="72" width="72"/><thr:total>0</thr:total><georss:featurename>Gurugram, Haryana, India</georss:featurename><georss:point>28.4594965 77.0266383</georss:point><georss:box>28.236063 76.7039148 28.68293 77.3493618</georss:box></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-6746983881468252841</guid><pubDate>Mon, 18 May 2020 08:53:00 +0000</pubDate><atom:updated>2020-05-24T05:51:05.467-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Apex Trigger</category><category domain="http://www.blogger.com/atom/ns#">Async</category><category domain="http://www.blogger.com/atom/ns#">Async Apex Trigger</category><category domain="http://www.blogger.com/atom/ns#">CDC</category><category domain="http://www.blogger.com/atom/ns#">Change Data Capture</category><category domain="http://www.blogger.com/atom/ns#">Lightning Web Component</category><category domain="http://www.blogger.com/atom/ns#">Ligthning</category><category domain="http://www.blogger.com/atom/ns#">LWC</category><category domain="http://www.blogger.com/atom/ns#">Platform Events</category><category domain="http://www.blogger.com/atom/ns#">Trigger</category><title>Part I : Understanding Change Data Capture using Asynchronous Apex Triggers and Handling Platform Event in Lightning Web Components</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Salesforce introduced Change Data Capture and Asynchronous Apex Triggers in Summer 19 release. Change Data Capture publishes change events, which represents changes to Salesforce records. Changes include the creation of a new record, updates to an existing record, deletion of a record, and undeletion of a record.&lt;br /&gt;
&lt;br /&gt;
Available in: both Salesforce Classic and Lightning Experience &lt;br /&gt;
Available in: Enterprise, Performance, Unlimited, and Developer editions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Use of Change Data Capture events to&lt;/u&gt;&lt;/b&gt;:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Receive notifications of Salesforce record changes, including create, update, delete, and undelete operations. &lt;/li&gt;
&lt;li&gt;Capture field changes for all records. &lt;/li&gt;
&lt;li&gt;Get broad access to all data regardless of sharing rules. &lt;/li&gt;
&lt;li&gt;Get information about the change in the event header, such as the origin of the change, which allows ignoring changes that your client generates. &lt;/li&gt;
&lt;li&gt;Perform data updates using transaction boundaries. &lt;/li&gt;
&lt;li&gt;Use a versioned event schema. &lt;/li&gt;
&lt;li&gt;Subscribe to mass changes in a scalable way. &lt;/li&gt;
&lt;li&gt;Get access to retained events for up to three days&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;&lt;u&gt;Supported Objects&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Change events are available for all custom objects defined in your Salesforce org and a subset of standard objects. To see the complete list of supported standard objects, please click &lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_object_support.htm&quot;&gt;here&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Understanding the Flow for Change Data Capture&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFsuXYAaaXMX9znoocWalqKhGr4W8xCfRnLu-DhsLPVsFolotVFfaiRzUJxt2XNbZVhM1UWhWQ68hdZm1GW0BtKBcn9NkqGLujrJjtdHSvDAQBPOl9cSYdqJLbpQCp-C00G29S-phkiLU/s1600/Screenshot+2020-05-18+at+12.18.27+PM.png&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFsuXYAaaXMX9znoocWalqKhGr4W8xCfRnLu-DhsLPVsFolotVFfaiRzUJxt2XNbZVhM1UWhWQ68hdZm1GW0BtKBcn9NkqGLujrJjtdHSvDAQBPOl9cSYdqJLbpQCp-C00G29S-phkiLU/s400/Screenshot+2020-05-18+at+12.18.27+PM.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
So when a record is created or updated, Change Data Capture publishes an event and a change event trigger can then process that event asynchronously. Above is a simple example to understand the flow better. Once any record completes its execution then change data publish an event and then Asynchronous Apex Trigger starts processing. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Setup Change Data Capture&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
First, we need to enable Change Data Capture for the object. In Setup Search for Change data Capture and open it. &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRYSFWxi1wgZwywBZ_KIb2cd-uk-3m2rEYATHYXP3J0zhMCoGO5xUaNehfGvZGajXE6aCKeAgbNXN63l07wFU_ZkjOFlI5Tv2X_8e5hDUZtEBq-MnUrQWhRcTrbYbWBaMc79c9nUXe0zI/s1600/Screenshot+2020-05-18+at+12.32.57+PM.png&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;224&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRYSFWxi1wgZwywBZ_KIb2cd-uk-3m2rEYATHYXP3J0zhMCoGO5xUaNehfGvZGajXE6aCKeAgbNXN63l07wFU_ZkjOFlI5Tv2X_8e5hDUZtEBq-MnUrQWhRcTrbYbWBaMc79c9nUXe0zI/s400/Screenshot+2020-05-18+at+12.32.57+PM.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
Once we have enabled it, we need to subscribe to the change events. To subscribe to the change events we will be using Subscribe with Apex Triggers. But before diving to apex triggers we need to understand the naming conventions for the channels which will be subscribing to the change. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt; Subscription Channels&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Use the subscription channel that corresponds to the change notifications you want to receive. The channel name is case-sensitive.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;All Change Events&lt;/b&gt;&lt;br /&gt;
&lt;div&gt;
/data/ChangeEvents&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;A Standard Object&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
/data/(Standar Object Name)&lt;standard_object_name&gt;ChangeEvent&lt;br /&gt; &lt;br /&gt;For example, the channel to subscribe to change events for Case records is:&lt;br /&gt;/data/CaseChangeEvent&lt;br /&gt; &lt;br /&gt;&lt;b&gt;A Custom Object&lt;/b&gt;&lt;/standard_object_name&gt;&lt;/div&gt;
&lt;div&gt;
/data/(Custom Object Name)&lt;custom_object_name&gt;__ChangeEvent&lt;br /&gt; &lt;br /&gt;For example, the channel to subscribe to change events for Candidate__c custom object records is:&lt;br /&gt;/data/Candidate__ChangeEvent&lt;br /&gt;&lt;br /&gt;If you want to learn more about Change Data Capture, please click &lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.change_data_capture.meta/change_data_capture/cdc_intro.htm&quot;&gt;here&lt;/a&gt;.&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt; Subscription Using Apex Triggers&lt;/u&gt;&lt;/b&gt;&lt;br /&gt; &lt;br /&gt; The change event trigger fires when one or a batch of change events is received. The change event trigger is not like object triggers, it runs asynchronously after the database transaction is completed. The asynchronous execution makes change event triggers ideal for processing resource-intensive business logic while keeping transaction-based logic in the object trigger. Change event triggers can help reduce transaction processing time.&lt;br /&gt; &lt;br /&gt; Below is the example:&lt;/custom_object_name&gt;&lt;br /&gt;
&lt;custom_object_name&gt;&lt;br /&gt;&lt;/custom_object_name&gt;
&lt;br /&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;trigger CaseChangeEventTrigger on CaseChangeEvent (after insert) {

    List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;CaseChangeEvent&amp;gt;&lt;/span&gt; changes = Trigger.new;
    
    Set&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;String&amp;gt;&lt;/span&gt; caseIds = new Set&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;String&amp;gt;&lt;/span&gt;();
    
    for (CaseChangeEvent change : changes) {
        // Get all Record Ids for this change and add to the set
        List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;String&amp;gt;&lt;/span&gt; recordIds = change.ChangeEventHeader.getRecordIds();
        caseIds.addAll(recordIds);
    }
    
    // Publish platform events for predicted red accounts
    List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;DemoLight12&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;__Case_Change_Event__e&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt; caseChangeEvents = new List&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;DemoLight12&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;__Case_Change_Event__e&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;();
    for (Case caseObj : [Select Id,CaseNumber from Case where Id in: caseIds]) {
        caseChangeEvents.add(new DemoLight12__Case_Change_Event__e(DemoLight12__CaseNumber__c=caseObj.CaseNumber));
    }
    
    System.debug(&#39;RED_ACCT: &#39; + caseChangeEvents);
    if (caseChangeEvents.size() &amp;gt; 0) {
        EventBus.publish(caseChangeEvents);
    }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
In the above code, I have created a platform event as Case_Change_Event__e, and by using EventBus.publish method I have published an event message.&lt;br /&gt;
&lt;br /&gt;
If you want to learn more about Platform Events, please click &lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_intro.htm&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Handling Platform Events in Lightning Components&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The &lt;b&gt;lightning/empApi&lt;/b&gt; module provides access to methods for subscribing to a streaming channel and listening to event messages. All streaming channels are supported, including channels for platform events, PushTopic events, generic events, and Change Data Capture events.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note:&lt;/b&gt;&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;This component is available in the 44.0 API version or later.&lt;/li&gt;
&lt;li&gt;This is available in Lightning Experience and only supported in desktop browsers.&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;Use case:&lt;/b&gt; I want to display a message on the Case Detail record page that particular case has been updated by others and the logged-in person is working on different cases, so on the case detail page logged in person will get a message displayed at the top which case has been updated. Below are the components I have used to achieve my use case:&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Setup Change Data Capture on Case object explained above.&lt;/li&gt;
&lt;li&gt;Create a Platform Event as Case_Change_Event__e and one custom field as Casenumber__c within the platform event object to store the CaseNumber which got updated.&lt;/li&gt;
&lt;li&gt;Create an Async Apex trigger as CaseChangeEventTrigger (explained above) to publish the platform event.&lt;/li&gt;
&lt;li&gt;Custom LWC component as caseChangeEvent which will subscribe to the platform event and will update the message on UI.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
Below is the code for the LWC component which will be added on the Case Detail record page and will subscribe to the platform event and display the message of any records got updated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;caseChangeEvent.html&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;template&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;lightning&lt;/span&gt;&lt;span style=&quot;color: #0000cc;&quot;&gt;-card&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;title=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;Pinned Updates on Cases&quot;&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;icon-name=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;custom:custom14&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;class=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;slds-m-around_medium&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
            {finalMessage}
        &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        
    &lt;span style=&quot;background-color: #ffaaaa; color: red;&quot;&gt;&amp;lt;&lt;/span&gt;/lightning-card&amp;gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;caseChangeEvent.js&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;import { LightningElement, api } from &#39;lwc&#39;;
import { subscribe, unsubscribe, onError, setDebugFlag, isEmpEnabled } from &#39;lightning/empApi&#39;;

export default class EmpApiLWC extends LightningElement {
    channelName = &#39;/event/DemoLight12__Case_Change_Event__e&#39;;
    isSubscribeDisabled = false;
    isUnsubscribeDisabled = !this.isSubscribeDisabled;

    message;

    renderedCallback() {
        const messageCallback = (response) =&amp;gt; {
            console.log(&#39;New message received : &#39;, JSON.stringify(response));
            // Response contains the payload of the new message received
            console.log(&#39;New message received : &#39;, response.data.payload.DemoLight12__CaseNumber__c);
            this.message = &#39;Case &#39; + response.data.payload.DemoLight12__CaseNumber__c + &#39; has been updated&#39;;
        };

        // Invoke subscribe method of empApi. Pass reference to messageCallback
        subscribe(this.channelName, -1, messageCallback).then(response =&amp;gt; {
            // Response contains the subscription information on successful subscribe call
            console.log(&#39;response === &#39; + JSON.stringify(response));
            console.log(&#39;Successfully subscribed to : &#39;, JSON.stringify(response.channel));
        })
    }

    registerErrorListener() {
        // Invoke onError empApi method
        onError(error =&amp;gt; {
            console.log(&#39;Received error from server: &#39;, JSON.stringify(error));
            // Error contains the server-side error
        });
    }

    get finalMessage(){
        return this.message;
    }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
If you observe in the above code I have imported lightning/empApi which provides below method&lt;br /&gt;
&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;subscribe - Subscribes to a given channel&lt;/li&gt;
&lt;li&gt;unsubscribe - Unsubscribes from the channel using the given subscription object&lt;/li&gt;
&lt;li&gt;onError - Registers a listener to errors that the server returns.&lt;/li&gt;
&lt;li&gt;setDebugFlag - Set to true or false to turn console logging on or off respectively.&lt;/li&gt;
&lt;li&gt;isEmpEnabled - Returns a promise that holds a Boolean value. The value is true if the EmpJs Streaming API library can be used in this context; otherwise false.&lt;/li&gt;
&lt;/ul&gt;
To learn more about lightning/empApi, please click &lt;a href=&quot;https://developer.salesforce.com/docs/component-library/bundle/lightning-emp-api&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;caseChangeEvent.js-meta.xml&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;!-- HTML generated using hilite.me --&gt;&lt;br /&gt;
&lt;div style=&quot;background: #ffffff; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;&quot;&gt;
&lt;pre style=&quot;line-height: 125%; margin: 0;&quot;&gt;&lt;span style=&quot;color: #557799;&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;LightningComponentBundle&lt;/span&gt; &lt;span style=&quot;color: #0000cc;&quot;&gt;xmlns=&lt;/span&gt;&lt;span style=&quot;background-color: #fff0f0;&quot;&gt;&quot;http://soap.sforce.com/2006/04/metadata&quot;&lt;/span&gt;&lt;span style=&quot;color: #007700;&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;apiVersion&amp;gt;&lt;/span&gt;48.0&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/apiVersion&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;isExposed&amp;gt;&lt;/span&gt;true&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/isExposed&amp;gt;&lt;/span&gt;
    &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;targets&amp;gt;&lt;/span&gt;
       &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;target&amp;gt;&lt;/span&gt;lightning__RecordPage&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/target&amp;gt;&lt;/span&gt;
   &lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/targets&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #007700;&quot;&gt;&amp;lt;/LightningComponentBundle&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;Live Demo:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.blogger.com/video.g?token=AD6v5dwqLqKyPIRkNcubkQv46NNmK6VnuZLtO8U-yp0LDLYYW89VcevXsnz3t4d25lnACzYmdf3QONLX4tVTp3yCzw&#39; class=&#39;b-hbp-video b-uploaded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;background-color: white; clear: both; color: #333333;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;I hope this will help to understand platform events handling in lightning components.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;background-color: white; clear: both; color: #333333;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;background-color: white; clear: both; color: #333333;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;times&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;Looking forward to everyone&#39;s suggestions and comments!!!&lt;/span&gt;&lt;/div&gt;
&lt;table border=&quot;0&quot; class=&quot;editionTable&quot; style=&quot;border-collapse: collapse; border-spacing: 0px; max-width: none; width: 100%;&quot; summary=&quot;Salesforce editions needed for the documented functionality&quot;&gt;&lt;tbody class=&quot;tbody&quot;&gt;
&lt;tr style=&quot;color: #333333; font-size: 15px;&quot;&gt;&lt;td class=&quot;subHead&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;color: #333333; font-size: 15px;&quot;&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</description><link>https://tandonprateek.blogspot.com/2020/05/understanding-change-data-capture-using.html</link><author>noreply@blogger.com (Prateek Tandon)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFsuXYAaaXMX9znoocWalqKhGr4W8xCfRnLu-DhsLPVsFolotVFfaiRzUJxt2XNbZVhM1UWhWQ68hdZm1GW0BtKBcn9NkqGLujrJjtdHSvDAQBPOl9cSYdqJLbpQCp-C00G29S-phkiLU/s72-c/Screenshot+2020-05-18+at+12.18.27+PM.png" height="72" width="72"/><thr:total>0</thr:total><georss:featurename>Gurugram, Haryana, India</georss:featurename><georss:point>28.4594965 77.0266383</georss:point><georss:box>28.236063 76.7039148 28.68293 77.3493618</georss:box></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-2635203535780671176</guid><pubDate>Mon, 29 Apr 2019 18:15:00 +0000</pubDate><atom:updated>2019-04-29T11:15:35.400-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Apex Method Imperatively</category><category domain="http://www.blogger.com/atom/ns#">Lightning Web Component</category><category domain="http://www.blogger.com/atom/ns#">LWC</category><category domain="http://www.blogger.com/atom/ns#">pagination</category><category domain="http://www.blogger.com/atom/ns#">wiring</category><title>LWC : Calling Apex Method, Pagination, Fetching Child Records and Use of Child Templates</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shCore.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCpp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCSharp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCss.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushDelphi.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJava.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJScript.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPhp.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPython.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushRuby.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushSql.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushVb.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushXml.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

&lt;script language=&quot;javascript&quot;&gt;
 
dp.SyntaxHighlighter.BloggerMode();
 
dp.SyntaxHighlighter.HighlightAll(&#39;code&#39;);
 
&lt;/script&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Hello guys, I am back with some new features of LWC. In this blog I will be covering the major features of LWC which we use on daily basis when we are coding with Visualforce or Aura components.&lt;br /&gt;
&lt;br /&gt;
In this blog I will be explaining how to display list of Accounts with Pagination and also I will be explaining how to display child records like Contacts related to respective Account. I will also explain how we can do insert operation on Account object.&lt;br /&gt;
&lt;br /&gt;
Let us start developing with lightning speed.&lt;br /&gt;
&lt;br /&gt;
First we will be creating a controller class.&lt;br /&gt;
&lt;br /&gt;
AccountController&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  public class AccountController {  
2:       @AuraEnabled(cacheable=true)  
3:    public static PagedResult getAccountList(Integer pageNumber) {  
4:      Integer pageSize = 3;  
5:      Integer offset = (pageNumber - 1) * pageSize;  
6:      PagedResult result = new PagedResult();  
7:      result.pageSize = pageSize;  
8:      result.pageNumber = pageNumber;  
9:      result.totalItemCount = Database.countQuery(&#39;SELECT count() from Account&#39;);  
10:      result.records = Database.query(&#39;SELECT Id, Name, AccountNumber, Phone, &#39;+  
11:                  &#39;(Select Id,Name from Contacts) contacts FROM Account&#39; +   
12:                  &#39; ORDER BY Name LIMIT :pageSize OFFSET :offset&#39;);  
13:      return result;  
14:    }  
15:    @AuraEnabled(cacheable=true)  
16:    public static List&amp;lt;Contact&amp;gt; getContactRecords(String accId){  
17:      return [Select Id,Name from Contact where AccountId =: accId];  
18:    }  
19:  }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
In the above code you guys must have noticed that I have used a wrapper class as &#39;PagedResult&#39;. This wrapper class is used to hold list of Account records and pageNumber, pageSize etc.&lt;br /&gt;
&lt;br /&gt;
&#39;PagedResult&#39; Wrapper class&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  public class PagedResult {  
2:    @AuraEnabled  
3:    public Integer pageSize { get;set; }  
4:    @AuraEnabled  
5:    public Integer pageNumber { get;set; }  
6:    @AuraEnabled  
7:    public Integer totalItemCount { get;set; }  
8:    @AuraEnabled  
9:    public Object[] records { get;set; }  
10:  }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Next, we will be creating LWC component to display list of Account records and pagination.&lt;br /&gt;
&lt;br /&gt;
accountList.html&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  &amp;lt;template&amp;gt;  
2:    &amp;lt;lightning-card title=&quot;Account List&quot; icon-name=&quot;custom:custom63&quot;&amp;gt;  
3:      &amp;lt;div class=&quot;slds-m-around_medium&quot;&amp;gt;  
4:        &amp;lt;template if:true={listMode}&amp;gt;  
5:          &amp;lt;template if:true={accounts.data}&amp;gt;  
6:            &amp;lt;table border=&quot;1&quot;&amp;gt;  
7:              &amp;lt;thead&amp;gt;  
8:                &amp;lt;tr&amp;gt;  
9:                  &amp;lt;th&amp;gt;  
10:                    Name  
11:                  &amp;lt;/th&amp;gt;  
12:                  &amp;lt;th&amp;gt;  
13:                    Number  
14:                  &amp;lt;/th&amp;gt;  
15:                  &amp;lt;th&amp;gt;  
16:                    Phone  
17:                  &amp;lt;/th&amp;gt;  
18:                  &amp;lt;th&amp;gt;  
19:                    Number of Contacts  
20:                  &amp;lt;/th&amp;gt;  
21:                &amp;lt;/tr&amp;gt;  
22:              &amp;lt;/thead&amp;gt;  
23:              &amp;lt;tbody&amp;gt;  
24:                &amp;lt;template for:each={accounts.data.records} for:item=&quot;acc&quot;&amp;gt;  
25:                  &amp;lt;tr key={acc.Id}&amp;gt;  
26:                    &amp;lt;td&amp;gt;{acc.Name}&amp;lt;/td&amp;gt;  
27:                    &amp;lt;td&amp;gt;{acc.AccountNumber}&amp;lt;/td&amp;gt;  
28:                    &amp;lt;td&amp;gt;{acc.Phone}&amp;lt;/td&amp;gt;  
29:                    &amp;lt;td&amp;gt;  
30:                      &amp;lt;c-numbercontactslink accountobj={acc} data-id={acc.Id} onclick={getAllContacts}&amp;gt;&amp;lt;/c-numbercontactslink&amp;gt;  
31:                      &amp;lt;!-- lightning-button variant=&quot;base&quot; label={acc.Contacts.length} title=&quot;Number of Contacts&quot; data-id={acc.Id} onclick={getAllContacts}&amp;gt;&amp;lt;/lightning-button --&amp;gt;  
32:                    &amp;lt;/td&amp;gt;  
33:                  &amp;lt;/tr&amp;gt;  
34:                &amp;lt;/template&amp;gt;  
35:              &amp;lt;/tbody&amp;gt;  
36:            &amp;lt;/table&amp;gt;  
37:            &amp;lt;c-pagination page-number={pageNumber} page-size={accounts.data.pageSize} total-item-count={accounts.data.totalItemCount}  
38:            onprevious={handlePreviousPage} onnext={handleNextPage}&amp;gt;&amp;lt;/c-pagination&amp;gt;  
39:            &amp;lt;lightning-button label=&quot;Create Account&quot; title=&quot;Create Account Record&quot; onclick={createAccount}&amp;gt;&amp;lt;/lightning-button&amp;gt;  
40:          &amp;lt;/template&amp;gt;  
41:        &amp;lt;/template&amp;gt;  
42:        &amp;lt;template if:true={createMode}&amp;gt;  
43:            &amp;lt;lightning-input label=&quot;Id&quot; disabled value={accountId}&amp;gt;&amp;lt;/lightning-input&amp;gt;  
44:            &amp;lt;lightning-input label=&quot;Name&quot; onchange={handleNameChange} class=&quot;slds-m-bottom_x-small&quot;&amp;gt;&amp;lt;/lightning-input&amp;gt;  
45:            &amp;lt;lightning-button label=&quot;Save Record&quot; variant=&quot;brand&quot; onclick={saveAccount}&amp;gt;&amp;lt;/lightning-button&amp;gt;  
46:            &amp;lt;lightning-button label=&quot;Cancel Record&quot; variant=&quot;brand&quot; onclick={cancelAccount}&amp;gt;&amp;lt;/lightning-button&amp;gt;  
47:        &amp;lt;/template&amp;gt;  
48:        &amp;lt;template if:true={showContacts}&amp;gt;  
49:          &amp;lt;lightning-card title=&quot;Related Contact List&quot; icon-name=&quot;custom:custom63&quot;&amp;gt;  
50:          &amp;lt;table&amp;gt;  
51:              &amp;lt;thead&amp;gt;  
52:                &amp;lt;tr&amp;gt;  
53:                  &amp;lt;th&amp;gt;  
54:                    Name  
55:                  &amp;lt;/th&amp;gt;  
56:                &amp;lt;/tr&amp;gt;  
57:              &amp;lt;/thead&amp;gt;  
58:              &amp;lt;tbody&amp;gt;  
59:                &amp;lt;template for:each={contacts} for:item=&quot;con&quot;&amp;gt;  
60:                  &amp;lt;tr key={con.Id}&amp;gt;  
61:                    &amp;lt;td&amp;gt;{con.Name}&amp;lt;/td&amp;gt;  
62:                  &amp;lt;/tr&amp;gt;  
63:                &amp;lt;/template&amp;gt;  
64:              &amp;lt;/tbody&amp;gt;  
65:            &amp;lt;/table&amp;gt;  
66:          &amp;lt;/lightning-card&amp;gt;  
67:        &amp;lt;/template&amp;gt;  
68:      &amp;lt;/div&amp;gt;  
69:    &amp;lt;/lightning-card&amp;gt;  
70:  &amp;lt;/template&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
accountList.js&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  import { LightningElement, wire, track} from &#39;lwc&#39;;  
2:  import { createRecord } from &#39;lightning/uiRecordApi&#39;;  
3:  import { ShowToastEvent } from &#39;lightning/platformShowToastEvent&#39;;  
4:  import { refreshApex } from &#39;@salesforce/apex&#39;;  
5:  import ACCOUNT_OBJECT from &#39;@salesforce/schema/Account&#39;;  
6:  import NAME_FIELD from &#39;@salesforce/schema/Account.Name&#39;;  
7:  import ACCNUMBER_FIELD from &#39;@salesforce/schema/Account.AccountNumber&#39;;  
8:  import getAccountList from &#39;@salesforce/apex/AccountController.getAccountList&#39;;  
9:  import getContactRecords from &#39;@salesforce/apex/AccountController.getContactRecords&#39;;  
10:  const CONTACT_FIELDS = [  
11:    &#39;Contact.Name&#39;,  
12:    &#39;Contact.Title&#39;,  
13:    &#39;Contact.Phone&#39;,  
14:    &#39;Contact.Email&#39;,  
15:  ];  
16:  export default class AccountListFunctionality extends LightningElement {  
17:    /** Current page in the account list. */  
18:    @track pageNumber = 1;  
19:    /** The number of items on a page. */  
20:    @track pageSize;  
21:    /** The total number of items matching the selection. */  
22:    @track totalItemCount = 0;  
23:    @wire(getAccountList, { pageNumber: &#39;$pageNumber&#39; })  
24:    accounts;  
25:    @track mode = &#39;list&#39;;  
26:    @track showContacts = false;  
27:    @track contacts;  
28:    createAccount(){  
29:      this.mode = &#39;create&#39;;  
30:    }  
31:    cancelAccount(){  
32:      this.mode = &#39;list&#39;;  
33:    }  
34:    handleNameChange(event) {  
35:      this.accountId = undefined;  
36:      this.name = event.target.value;  
37:      this.accnumber = event.target.value;  
38:    }  
39:    get listString() {  
40:      return JSON.stringify(this.accounts);  
41:    }  
42:    saveAccount() {  
43:      const fields = {};  
44:      fields[NAME_FIELD.fieldApiName] = this.name;  
45:      fields[ACCNUMBER_FIELD.fieldApiName] = this.accnumber;  
46:      const recordInput = { apiName: ACCOUNT_OBJECT.objectApiName, fields };  
47:      createRecord(recordInput)  
48:        .then(account =&amp;gt; {  
49:          this.accountId = account.id;  
50:          this.mode = &#39;list&#39;;  
51:          this.dispatchEvent(  
52:            new ShowToastEvent({  
53:              title: &#39;Success&#39;,  
54:              message: &#39;Account created&#39;,  
55:              variant: &#39;success&#39;,  
56:            }),  
57:          );  
58:        }).then(() =&amp;gt; {  
59:          return refreshApex(this.accounts);  
60:        })  
61:        .catch(error =&amp;gt; {  
62:          this.dispatchEvent(  
63:            new ShowToastEvent({  
64:              title: &#39;Error creating record&#39;,  
65:              message: error.message,  
66:              variant: &#39;error&#39;,  
67:            }),  
68:          );  
69:        });  
70:    }  
71:    get listMode(){  
72:      if(this.mode === &#39;list&#39;){  
73:        return true;  
74:      }  
75:      return false;  
76:    }  
77:    get createMode(){  
78:      if(this.mode === &#39;create&#39;){  
79:        return true;  
80:      }  
81:      return false;  
82:    }  
83:    handlePreviousPage() {  
84:      this.pageNumber = this.pageNumber - 1;  
85:    }  
86:    handleNextPage() {  
87:      this.pageNumber = this.pageNumber + 1;  
88:    }  
89:    getAllContacts(event){  
90:      this.showContacts = true;  
91:      let accId = event.target.getAttribute(&#39;data-id&#39;);  
92:      console.log(&#39;acc id ==== &#39; + accId);  
93:      getContactRecords({accId})  
94:        .then(result =&amp;gt; {  
95:          this.contacts = result;  
96:        })  
97:        .catch(error =&amp;gt; {  
98:          this.error = error;  
99:        });  
100:    }   
101:  }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&#39;pagination.html&#39; LWC Component&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  &amp;lt;template&amp;gt;  
2:    &amp;lt;lightning-layout vertical-align=&quot;center&quot; class=&quot;slds-m-horizontal_x-small&quot;&amp;gt;  
3:      &amp;lt;lightning-layout-item size=&quot;2&quot;&amp;gt;  
4:        &amp;lt;template if:false={isFirstPage}&amp;gt;  
5:          &amp;lt;lightning-button-icon icon-name=&quot;utility:chevronleft&quot; onclick={handlePrevious}&amp;gt;&amp;lt;/lightning-button-icon&amp;gt;  
6:        &amp;lt;/template&amp;gt;    
7:      &amp;lt;/lightning-layout-item&amp;gt;  
8:      &amp;lt;lightning-layout-item size=&quot;8&quot; class=&quot;nav-info&quot;&amp;gt;  
9:        {totalItemCount} items • page {currentPageNumber} of {totalPages}  
10:      &amp;lt;/lightning-layout-item&amp;gt;  
11:      &amp;lt;lightning-layout-item size=&quot;2&quot; class=&quot;nav-next&quot;&amp;gt;  
12:        &amp;lt;template if:false={isLastPage}&amp;gt;  
13:          &amp;lt;lightning-button-icon icon-name=&quot;utility:chevronright&quot; onclick={handleNext}&amp;gt;&amp;lt;/lightning-button-icon&amp;gt;  
14:        &amp;lt;/template&amp;gt;  
15:      &amp;lt;/lightning-layout-item&amp;gt;  
16:    &amp;lt;/lightning-layout&amp;gt;  
17:  &amp;lt;/template&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&#39;pagination.js&#39;&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  import { LightningElement, api } from &#39;lwc&#39;;  
2:  export default class Paginator extends LightningElement {  
3:    /** The current page number. */  
4:    @api pageNumber;  
5:    /** The number of items on a page. */  
6:    @api pageSize;  
7:    /** The total number of items in the list. */  
8:    @api totalItemCount;  
9:    handlePrevious() {  
10:      this.dispatchEvent(new CustomEvent(&#39;previous&#39;));  
11:    }  
12:    handleNext() {  
13:      this.dispatchEvent(new CustomEvent(&#39;next&#39;));  
14:    }  
15:    get currentPageNumber() {  
16:      return this.totalItemCount === 0 ? 0 : this.pageNumber;  
17:    }  
18:    get isFirstPage() {  
19:      return this.pageNumber === 1;  
20:    }  
21:    get isLastPage() {  
22:      return this.pageNumber &amp;gt;= this.totalPages;  
23:    }  
24:    get totalPages() {  
25:      return Math.ceil(this.totalItemCount / this.pageSize);  
26:    }  
27:  }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&#39;numberconatctslink.html&#39; LWC Component&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  &amp;lt;template&amp;gt;  
2:      &amp;lt;lightning-button variant=&quot;base&quot; label={labelName} title=&quot;Number of Contacts&quot;&amp;gt;&amp;lt;/lightning-button&amp;gt;  
3:    &amp;lt;/template&amp;gt;  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
numbercontactslink.js&lt;br /&gt;
&lt;pre style=&quot;background: #f0f0f0; border: 1px dashed #cccccc; color: black; font-family: &amp;quot;arial&amp;quot;; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;1:  import { LightningElement, track, api } from &#39;lwc&#39;;  
2:  export default class Numbercontactslink extends LightningElement {  
3:    @api labelName;  
4:    @api accountRec;  
5:    @api  
6:    get accountobj() {  
7:      return this.accountRec;  
8:    }  
9:    set accountobj(value){  
10:      this.accountRec = value;  
11:      if(this.accountRec.Contacts != undefined){  
12:        this.labelName = this.accountRec.Contacts.length;  
13:      }else{  
14:        this.labelName = 0;  
15:      }  
16:    }  
17:  }  
&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Working Demo:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.blogger.com/video.g?token=AD6v5dwfn3lSXi5Y0BaCoZjx29F83vvjbzC_vnoyh8C_4jbKKNAr4R2Z4yT2rjJXloJ5QXtP9Fn3WdiLD83R0mfnmw&#39; class=&#39;b-hbp-video b-uploaded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://tandonprateek.blogspot.com/2019/04/lwc-calling-apex-method-pagination.html</link><author>noreply@blogger.com (Prateek Tandon)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-6400519409822795892</guid><pubDate>Sat, 26 Jan 2019 18:50:00 +0000</pubDate><atom:updated>2019-01-26T11:01:10.944-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Lightning Web Component</category><category domain="http://www.blogger.com/atom/ns#">LWC</category><title>Lightning Web Component : My First Web Component</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #444444; font-family: Raleway-SemiBold !important; font-size: 1.24286rem; line-height: 1.84615; margin: 0.314286rem 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;border: 0px; box-sizing: inherit; color: black; font-size: 17.4px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;What are Lightning Web Components?&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Now you can build Lightning components using two programming models: Lightning Web Components (LWC), and the original model, Aura Components. Lightning web components (LWC) are custom HTML elements built using HTML and modern JavaScript. Lightning web components and Aura components can coexist and interoperate on a page. To admins and end users, they both appear as Lightning components.&lt;br /&gt;&lt;br /&gt;Lightning Web Components (LWC) uses core Web Components standards and provides only what’s necessary to perform well in browsers supported by Salesforce. Because it’s built on code that runs natively in browsers, Lightning Web Components is lightweight and delivers exceptional performance. Most of the code you write is standard JavaScript and HTML.&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; font-family: Raleway-SemiBold !important; line-height: 1.84615; margin: 0.314286rem 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;font-size: 17.4px;&quot;&gt;Is it necessary to learn Lightning Component before we start with LWC?&lt;/span&gt;&lt;/h3&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Not necessary, knowledge of Lightning Component will be an add-on to understand LWC easily but it is not mandatory. We can directly start learning LWC with the help of &lt;a href=&quot;https://developer.salesforce.com/docs/component-library/documentation/lwc&quot;&gt;Lightning Web Component Library&lt;/a&gt; provided by Salesforce.&lt;/span&gt;&lt;br /&gt;
&lt;h3 style=&quot;background-color: white; border: 0px; box-sizing: inherit; clear: both; color: #444444; font-family: Raleway-SemiBold !important; font-size: 1.24286rem; line-height: 1.84615; margin: 0.314286rem 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;border: 0px; box-sizing: inherit; color: black; font-size: 17.4px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;How to create a Lightning Web Component?&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;border: 0px; box-sizing: inherit; color: black; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;We cannot create LWC directly from our developer console. We need to have SFDX to create our own LWC. Other prerequisite to create LWC are as follows:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;VS Code Editor&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Salesforce Extension Pack (Extension for VS Code)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Lightning Web Components (Extension for VS Code)&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Salesforce CLI Command Tool&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;SFDX&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Creating first Component: Temperature Calculation&lt;/h4&gt;
&lt;/div&gt;
&lt;div&gt;
I have tried to create a simple component which calculates temperature calculation centigrade to fahrenheit or vice versa. Please ignore bad UI representation I am not good into CSS and UI representation.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;TempConverter.html&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;lt;template&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;lt;lightning-card title=&quot;Temperature Converter&quot; icon-name=&quot;standard:formula&quot;&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;lightning-layout multiple-rows=&quot;true&quot;&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;lightning-layout-item size=&quot;12&quot; padding=&quot;around-small&quot;&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;lightning-input type=&quot;number&quot; label=&quot;In Centigrade&quot;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; name=&quot;centigrade&quot; onchange={onNumberChange}&amp;gt;&amp;lt;/lightning-input&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/lightning-layout-item&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;lightning-layout-item size=&quot;12&quot; padding=&quot;around-small&quot;&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;p class=&quot;slds-m-top_medium&quot; style=&quot;color:blue; font-weight:bold;&quot;&amp;gt;{&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; finalFahrenheitresult}&amp;lt;/p&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/lightning-layout-item&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;lightning-layout-item size=&quot;12&quot; padding=&quot;around-small&quot;&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;lightning-input type=&quot;number&quot; label=&quot;In Fahrenheit&quot;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; name=&quot;fahrenheit&quot; onchange={onNumberChange}&amp;gt;&amp;lt;/lightning-input&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/lightning-layout-item&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;lightning-layout-item size=&quot;12&quot; padding=&quot;around-small&quot;&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;p class=&quot;slds-m-top_medium&quot; style=&quot;color:blue; font-weight:bold;&quot;&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {finalCentigraderesult}&amp;lt;/p&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/lightning-layout-item&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/lightning-layout&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;lt;/lightning-card&amp;gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;lt;/template&amp;gt;&lt;/blockquote&gt;
&lt;/span&gt;&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;TempConverter.js&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;import { LightningElement, track } from &#39;lwc&#39;;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;export default class TempConverter extends LightningElement {&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; @track centigradeValue;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; @track fahrenheitValue;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; @track centigradeResult;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; @track fahrenheitResult;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; /**&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* This method will be called when either centrigade or fahrenheit value&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* is changed&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* Accordingly it will set the centrigade or fahrenheit property in&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* javascript&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* @author Prateek Tandon&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* @param {} event&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; onNumberChange(event){&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; const tagName = event.target.name;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(tagName === &quot;centigrade&quot;){&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.centigradeValue = event.target.value;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(this.centigradeValue !== &#39;&#39;){&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.fahrenheitResult = (this.centigradeValue * 1.8)+32;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }else{&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.fahrenheitResult = &#39;&#39;;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }else{&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.fahrenheitValue = event.target.value;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(this.fahrenheitValue !== &#39;&#39;){&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.centigradeResult = (this.fahrenheitValue-32)*0.55;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }else{&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; this.centigradeResult = &#39;&#39;;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; /**&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* Property getter&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* This method will automatically be called when fahrenheitResult value&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* is changed. This getter method can be easily accessed in template using&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* {finalFahrenheitresult}&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* @author Prateek Tandon&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; get finalFahrenheitresult(){&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(this.fahrenheitResult === 0 || this.fahrenheitResult){&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return &#39;Value in Fahrenheit &#39; + this.fahrenheitResult;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return &#39;&#39;;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; /**&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* Property getter&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* This method will automatically be called when centigradeResult value&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* is changed. This getter method can be easily accessed in template using&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* {finalCentigraderesult}&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* @author Prateek Tandon&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; get finalCentigraderesult(){&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(this.centigradeResult === 0 || this.centigradeResult){&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return &#39;Value in Fahrenheit &#39; + this.centigradeResult;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return &#39;&#39;;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;}&lt;/span&gt;&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;TempConverter.js-meta.xml&lt;/span&gt;&lt;/div&gt;
&lt;b style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;lt;LightningComponentBundle xmlns=&quot;http://soap.sforce.com/2006/04/metadata&quot;&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;fqn=&quot;TempConverter&quot;&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;apiVersion&amp;gt;45.0&amp;lt;/apiVersion&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;isExposed&amp;gt;true&amp;lt;/isExposed&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;targets&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;target&amp;gt;lightning__AppPage&amp;lt;/target&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;target&amp;gt;lightning__RecordPage&amp;lt;/target&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;target&amp;gt;lightning__HomePage&amp;lt;/target&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;nbsp; &amp;lt;/targets&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;&amp;lt;/LightningComponentBundle&amp;gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;b style=&quot;color: #0b5394;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style=&quot;color: #0b5394;&quot;&gt;Output:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;iframe allowfullscreen=&#39;allowfullscreen&#39; webkitallowfullscreen=&#39;webkitallowfullscreen&#39; mozallowfullscreen=&#39;mozallowfullscreen&#39; width=&#39;320&#39; height=&#39;266&#39; src=&#39;https://www.blogger.com/video.g?token=AD6v5dwaBMARTkR3GwTLHe541goXs4qbV007l2CXyDwRQpdZRiuoiiD1X_wzfnB3cYHeBdQj0U37EkYxPqWNXMoXSQ&#39; class=&#39;b-hbp-video b-uploaded&#39; frameborder=&#39;0&#39;&gt;&lt;/iframe&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;This is the simplest Lightning Web Component that I have created. Please let me know if you find any scope of improvement and I am still learning LWC components.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://tandonprateek.blogspot.com/2019/01/lightning-web-component-my-first-web.html</link><author>noreply@blogger.com (Prateek Tandon)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-623632917225910672.post-4375904242188555241</guid><pubDate>Tue, 15 Jan 2019 17:38:00 +0000</pubDate><atom:updated>2019-01-15T09:43:17.777-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">case team roles</category><category domain="http://www.blogger.com/atom/ns#">case team salesforce</category><category domain="http://www.blogger.com/atom/ns#">case teams</category><category domain="http://www.blogger.com/atom/ns#">predefined case teams</category><title>Case Teams</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; color: #222222; font-size: 16px;&quot;&gt;What are&amp;nbsp;&lt;b&gt;Case Teams&lt;/b&gt;?&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; color: #222222; font-size: 16px;&quot;&gt;A&amp;nbsp;&lt;b&gt;case team&lt;/b&gt;&amp;nbsp;is a group of people that work together to solve&amp;nbsp;&lt;b&gt;cases&lt;/b&gt;. They provide a clear way to document the roles of multiple users in the management of a single case. They also extend record access to team members&amp;nbsp;(which can include community users). For example, a&amp;nbsp;&lt;b&gt;case team&lt;/b&gt;&amp;nbsp;can include support agents, support managers, and product managers.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;h2 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; color: #222222; font-size: 16px;&quot;&gt;Configuring Case Teams&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; color: #222222; font-size: 16px;&quot;&gt;1. Define Team Roles Mo&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; color: #222222; font-size: 16px;&quot;&gt;Navigate to Setup -&amp;gt; Customize -&amp;gt; Cases -&amp;gt; Case Teams -&amp;gt; Case Team Roles&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;span style=&quot;background-color: white; color: #222222; font-size: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipW-4mcrOxUqQuFXzs4lHOE_VCUMqjVauA8rkTGaughf2Y5NkD2YNiOFBsYvprMHWUGzFXcIfOqWJZWe1LEZuGFWKYD2lm4LH0_iv7udAXDsFf8UtHjyscC3J6SIMuKuJd1u4ZG2oMfMQ/s1600/Screenshot+2019-01-15+at+8.21.19+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;512&quot; data-original-width=&quot;1478&quot; height=&quot;138&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipW-4mcrOxUqQuFXzs4lHOE_VCUMqjVauA8rkTGaughf2Y5NkD2YNiOFBsYvprMHWUGzFXcIfOqWJZWe1LEZuGFWKYD2lm4LH0_iv7udAXDsFf8UtHjyscC3J6SIMuKuJd1u4ZG2oMfMQ/s400/Screenshot+2019-01-15+at+8.21.19+PM.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;clear: both;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: small;&quot;&gt;2. Modification on Case Page Layout&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Navigate to Setup -&amp;gt; Customize -&amp;gt; Cases -&amp;gt; Page Layouts&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Add the Case Team related list to each case page layout:&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoT8MxFbQ98oHlHXw5l54SqYfDCI9ndumkB0TfvGqX_Vuhyphenhyphend-VaZOAcdtZu5cuNxd0I3VQzocK7qnVI4crP88xIYaup3V2brxVTbdkWMSQEyfPRFfgXvbOauskyPS5w2beNKqQXeXDHHg/s1600/Screenshot+2019-01-15+at+8.27.41+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;155&quot; data-original-width=&quot;1600&quot; height=&quot;37&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoT8MxFbQ98oHlHXw5l54SqYfDCI9ndumkB0TfvGqX_Vuhyphenhyphend-VaZOAcdtZu5cuNxd0I3VQzocK7qnVI4crP88xIYaup3V2brxVTbdkWMSQEyfPRFfgXvbOauskyPS5w2beNKqQXeXDHHg/s400/Screenshot+2019-01-15+at+8.27.41+PM.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h2 style=&quot;clear: both;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;h2 style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;h2 style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif; font-size: small;&quot;&gt;Predefined Case Teams&lt;/span&gt;&lt;/h2&gt;
&lt;div style=&quot;clear: both;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;There is one more great feature provided by salesforce&amp;nbsp;through which we can predefine case teams so that support agents can quickly add people who they frequently work with cases.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;clear: both;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Navigate to Setup -&amp;gt; Customize -&amp;gt; Cases -&amp;gt; Case Teams -&amp;gt; Predefined Case Teams&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWdT-mbkG1Pvxsk94TMlH0kiPoucpeAOgzK76-m5HpQIk5yVQ0e4OpWcvhmXQH6AMQxrAlKtYOAyCDEVzO9z1B44AcRpg6eB_nw6NhpQGQW2s2wtwNi4vsb-bC4SIaiw8NYg5cLKgep54/s1600/Screenshot+2019-01-15+at+8.38.25+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;760&quot; data-original-width=&quot;1600&quot; height=&quot;187&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWdT-mbkG1Pvxsk94TMlH0kiPoucpeAOgzK76-m5HpQIk5yVQ0e4OpWcvhmXQH6AMQxrAlKtYOAyCDEVzO9z1B44AcRpg6eB_nw6NhpQGQW2s2wtwNi4vsb-bC4SIaiw8NYg5cLKgep54/s400/Screenshot+2019-01-15+at+8.38.25+PM.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Above we have seen how we can set up or manage&amp;nbsp;&lt;b&gt;Case Teams&lt;/b&gt;&amp;nbsp;using point and click. Now let us see if the developer has to manage&amp;nbsp;&lt;b&gt;Case Teams&lt;/b&gt;&amp;nbsp;through code so what all objects will be included.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Below are the objects which are included to manage the Case Teams functionality&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;/div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.214.0.api.meta/api/sforce_api_objects_caseteammember.htm&quot;&gt;CaseTeamMember&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.214.0.api.meta/api/sforce_api_objects_caseteamrole.htm&quot;&gt;CaseTeamRole&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.214.0.api.meta/api/sforce_api_objects_caseteamtemplate.htm&quot;&gt;CaseTeamTemplate&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.214.0.api.meta/api/sforce_api_objects_caseteamtemplatemember.htm&quot;&gt;CaseTeamTemplateMember&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;a href=&quot;https://developer.salesforce.com/docs/atlas.en-us.214.0.api.meta/api/sforce_api_objects_caseteamtemplaterecord.htm&quot;&gt;CaseTeamTemplateRecord&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;To manage Predefined Case Team functionality CaseTeamTemplate, CaseTeamTemplateMember, and CaseTeamTemplateRecord objects are used.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;CaseTeamTemplateRecord object works as a linking object between Case and CaseTeamTemplate objects.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;Below is the sample code which helps to understand the relationship for&amp;nbsp;&lt;b&gt;Predefined Case Team&lt;/b&gt;&amp;nbsp;functionality:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
&lt;span class=&quot;il&quot;&gt;CaseTeamTemplate&lt;/span&gt;&amp;nbsp;cttObj = new&amp;nbsp;&lt;span class=&quot;il&quot;&gt;CaseTeamTemplate&lt;/span&gt;(Description = &#39;Group of agents to which case can be assigned.&#39;,Name = &#39;Support Agent&#39;);&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
insert cttObj;&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
List&amp;lt;CaseTeamTemplateMember&amp;gt; cttmList = new List&amp;lt;CaseTeamTemplateMember&amp;gt;()&lt;wbr&gt;&lt;/wbr&gt;;&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
cttmList.add(new CaseTeamTemplateMember(&lt;wbr&gt;&lt;/wbr&gt;MemberId = &#39;005XXXXXXXXXXXX&#39;,TeamRoleId = &#39;0B7XXXXXXXXXXXX&#39;,&lt;wbr&gt;&lt;/wbr&gt;TeamTemplateId = cttObj.Id));&lt;u&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
cttmList.add(new CaseTeamTemplateMember(&lt;wbr&gt;&lt;/wbr&gt;MemberId = &#39;005YYYYYYYYYYYY&#39;,TeamRoleId = &#39;0B7YYYYYYYYYYYY&#39;,&lt;wbr&gt;&lt;/wbr&gt;TeamTemplateId = cttObj.Id));&lt;u&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
insert cttmList;&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
//Run below lines after executing above lines because it gives MIXED_DML error when executed simultaneously&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
//CaseTeamTemplateRecord is a juntion object between Case and&amp;nbsp;&lt;span class=&quot;il&quot;&gt;CaseTeamTemplate&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
List&amp;lt;&lt;span class=&quot;il&quot;&gt;CaseTeamTemplate&lt;/span&gt;&amp;gt; cttlist = [Select Id from&amp;nbsp;&lt;span class=&quot;il&quot;&gt;CaseTeamTemplate&lt;/span&gt;&amp;nbsp;where Name = &#39;Admin&#39;];&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
CaseTeamTemplateRecord cttrObj = new CaseTeamTemplateRecord(&lt;wbr&gt;&lt;/wbr&gt;ParentId = &#39;500ZZZZZZZZZZZZ&#39;,&lt;wbr&gt;&lt;/wbr&gt;TeamTemplateId = cttlist[0].Id);&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin-bottom: 12pt;&quot;&gt;
insert cttrObj;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: &amp;quot;arial&amp;quot; , &amp;quot;helvetica&amp;quot; , sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;clear: both;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;-webkit-text-stroke-width: 0px; color: black; font-family: Times; font-size: medium; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: normal; margin: 0px; orphans: 2; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>https://tandonprateek.blogspot.com/2019/01/case-teams-in-salesforce.html</link><author>noreply@blogger.com (Prateek Tandon)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipW-4mcrOxUqQuFXzs4lHOE_VCUMqjVauA8rkTGaughf2Y5NkD2YNiOFBsYvprMHWUGzFXcIfOqWJZWe1LEZuGFWKYD2lm4LH0_iv7udAXDsFf8UtHjyscC3J6SIMuKuJd1u4ZG2oMfMQ/s72-c/Screenshot+2019-01-15+at+8.21.19+PM.png" height="72" width="72"/><thr:total>0</thr:total></item></channel></rss>