<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hari Baskar S on Medium]]></title>
        <description><![CDATA[Stories by Hari Baskar S on Medium]]></description>
        <link>https://medium.com/@hari626007?source=rss-79f4c19c681b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7fWesHBX0VfoFItm</url>
            <title>Stories by Hari Baskar S on Medium</title>
            <link>https://medium.com/@hari626007?source=rss-79f4c19c681b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 07:33:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hari626007/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Salesforce Named Credential: OAuth based Authentication by implementing Salesforce to Salesforce…]]></title>
            <link>https://medium.com/@hari626007/salesforce-named-credential-oauth-based-authentication-by-implementing-salesforce-to-salesforce-9462cdde2fbc?source=rss-79f4c19c681b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9462cdde2fbc</guid>
            <category><![CDATA[named-credential]]></category>
            <category><![CDATA[salesforce-to-salesforce]]></category>
            <category><![CDATA[oauth-authentication]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Hari Baskar S]]></dc:creator>
            <pubDate>Fri, 13 Nov 2026 03:32:34 GMT</pubDate>
            <atom:updated>2026-11-13T03:32:34.695Z</atom:updated>
            <content:encoded><![CDATA[<h3>Salesforce Named Credential: OAuth based Authentication by implementing Salesforce to Salesforce Integration</h3><p>In this article, I would be covering two topics together:</p><ul><li>How to make use of Named Credentials for OAuth based Authentication</li><li>How to perform Salesforce to Salesforce Integration via REST API</li></ul><p>Both are covered in the same article because the Resource Server am going to use for the OAuth Demo is going to be another Salesforce and the OAuth Client duh, is also a Salesforce Org. If you want, you try implementing any other OAuth Resource Server that you have based on which the setup becomes ridiculously simple.</p><p><strong>A SMALL INTRO ON CREDENTIALS &amp; EXTERNAL CLIENT APP:</strong></p><p><strong>Credentials:</strong></p><p>This helps in making callout to External Services from Salesforce (which you can already once you configure the URL in Remote Site Settings but here the add-on is that you can handle Authentication also via External Credential).</p><p>These Credential is composed two Entities:</p><ul><li>Named Credential =&gt; Which contains the URL of the external service, related header configs and this related to an External Credential.</li><li>External Credential =&gt; These are the core for Named Credentials (can be shared across multiple Named Credentials) which helps in performing Authentication via Bearer Token, OAuth etc.</li></ul><p><strong>External Client App:</strong></p><p>Whenever any external entity is going to need to access a resource of Salesforce we would need an External Client App. This is where we would be configuring the OAuth Configuration which can be then shared with the External Entity which would be making the Authenticated callout to access the resources of Salesforce.</p><p>So in our case we would be:</p><ul><li>Creating an External Client App in an Org which I would refer as the OAuth Resource Server (Mimicking any other OAuth Resource you would want to connect via Named Credential)</li><li>Creating a Named Credential in an Org which I would refer as the OAuth Client with the details from the Resource Server Org thus establishing the connection for the SF to SF Integration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNXnyyBCo8RkvtZvVLNLqQ.png" /></figure><blockquote><strong><em>Using a non-Salesforce server?</em></strong><em> Skip the Org B setup. You only need its Client ID, Client Secret, Token Endpoint, and API Endpoint.</em></blockquote><p><strong>IMPLEMENTATION:</strong></p><p><strong>Configuration in Org B (Salesforce as OAuth Server )— ECA:</strong></p><p>NOTE: This is required only if you want to have another Salesforce Server as the resource server. If not just make sure that you have the below information from whichever resource server you are going to access:</p><ul><li>Client ID</li><li>Client Secret</li><li>Token Endpoint</li><li>API Endpoint</li></ul><p>Continuing on the ECA Creation:</p><ul><li>Go to Setup &gt; External Client App Manager &gt; New</li><li>Provide the required basic fields like Name, API Name, Contact Email etc.</li><li>Under API (Enable OAuth Settings), enable OAuth:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tpj1dnpLETHT6GkAyA4RkQ.png" /></figure><ul><li>Callback URL is a required field but it doesn’t have any impact for Client Credential Flow so we can just provide a dummy URL over here.</li><li>Include api scope as we will be making REST API Callouts from the OAuth Client Org or any other scope that you would need based on your requirement.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Whgo2fH7fpCJiPYXQPFPQ.png" /></figure><ul><li>In Flow Enablement, enable Client Credential Flow:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*cYLjTH0mNb-YbfwpuNtzGA.png" /></figure><p>And create it. Once we create it, the ECA will have 3 tabs:</p><ul><li>Policy</li><li>Settings</li><li>Package Default</li></ul><p>The above OAuth config we did would be in the Settings Tab but now we would have to go to <strong>Policy tab</strong> &gt; Edit:</p><ul><li>Enable Client Credential Flow here once again and provide the running user’s username:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Uj0QkXpEC2yXtUP6-_KaQ.png" /></figure><p>and save it. Now we can go to the <strong>Settings Tab</strong> of the ECA &gt; OAuth Settings &amp; get the Consumer Key &amp; Secret too:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ZBxpFMsrN-JnpsQ4r9YBQ.png" /></figure><p>With this the ECA Config for the OAuth Resource Org is done.</p><p><strong>Configuration in Org A — Named Credential:</strong></p><ul><li>Setup &gt; Named Credential, we have two tabs:<br>- Named Credentials<br>- External Credentials</li><li>First we would have to create the External Credential. So go the EC Tab &gt; New</li><li>Provide the Name &amp; Label and<br>- Provide the Authentication Protocol as OAuth 2.0<br>- Authentication Flow Type as Client Credentials with Client Secret Flow<br>- Leave the scope as empty (as whatever is configured in the ECA is what would be applied by default)<br>- Identity Provider URL as the Token Endpoint URL of the OAuth Authentication server and Save it.</li></ul><p>NOTE: To get the Token Endpoint URL of any we can go to <strong>https://myorgdomain.my.salesforce.com/.well-known/openid-configuration which in our case must be obtained from Org B:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CH-KKhdIl86qNHmO3JOE8g.png" /></figure><p>And here we can get the <strong>token_endpoint </strong>property and push it into the Identity URL Endpoint of the Ext Creds.</p><ul><li>Now in the External Cred, if we scroll down we have a section <strong>Principals. </strong>Click on New in the Principal and then provide the Principal Name (can be anything) and populate the Client Id &amp; Secret that was obtained from the ECA (or your own OAuth Server) and Save it.</li></ul><p>Continuing on configuring Named Cred, we can now create the Named Cred as:</p><ul><li>Setup &gt; Named Cred &gt; Named Credential Tab &gt; New</li><li>Provide Name &amp; Label.</li><li>For URL, provide the Org My Domain URL (or OAuth Resource Server URL based on your need)</li><li>Make sure Enabled for Callout is enabled.</li><li>Choose the Ext Cred as the one that was created in the above steps.</li><li>Make sure <strong>Generate Authorization Header </strong>is enabled. This is what would instruct Salesforce to call the Token endpoint with the Ext Creds Configuration to get a Bearer Token which would be then automatically set in the Authorization Header.</li><li>Save it.</li></ul><p>This would then look like something below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uP3uwjLZ9GKwxGaMqOJcDw.png" /></figure><p>Now the configuration for the Named Credential &amp; External Credential is done but if you make a callout, it would fail because we haven’t granted access to the External Credential Principal that we created above. So to do that in any existing PS or New PS:</p><ul><li>Setup &gt; Permission Set &gt; External Credential Principal Access &gt; Add the above created Principal and save it.</li><li>Assign it to the required users.</li></ul><p><strong>VALIDATION:</strong></p><p>So to summarise what we have done till now:</p><ul><li>We have created a ECA in Org B</li><li>Created a Named &amp; External Credential in Org A and provided access to the External Credential Principal to the required users.</li></ul><p>So ECA acts as the way to provide access to the Org and Named Credentials acts as the way to perform the authentication via OAuth. Now on executing an anonymous script below:</p><pre>HttpRequest req = new HttpRequest();<br>req.setEndpoint(&#39;callout:OAuth_Named_Creds/services/data/v66.0/limits&#39;);<br>req.setMethod(&#39;GET&#39;);<br>Http http = new Http();<br>HttpResponse resp = http.send(req);<br>System.debug(JSON.serializePretty(JSON.deserializeUntyped(resp.getBody())));</pre><p>(Just a simple script to hit a Standard Limits API exposed by Salesforce)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*djJjJyBR571Lef-rbbi0OA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*T-4l0ThPUSecLMVYH8KkHw.png" /></figure><p>So in here, as I make the callout via Named Credential, Salesforce generated the OAuth Token via the Client Credential Flow with the Client Id &amp; Secret configured in it’s associated External Credential and used it make the callout to the other Salesforce Org.</p><p>One more interesting thing to note is even though this is technically 2 callouts done, if we check out the limits utilisation at the end of the logs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*WqjlF4ruproBIyEPMONDCQ.png" /></figure><p>We can see it has consumed only 1 callout.</p><p><strong>CONCLUSION:</strong></p><p>So, I hope this helps in configuring your Named Creds for OAuth Authentication or implementing SF to SF Integration. Once we open up the REST API of the Org, we expose a lot of functionality for integration like Custom Apex REST API, Standard sObject API for CRUD, Trigger Platform events etc. Its upto you on how to use it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9462cdde2fbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[@lwc/state Explained: LWC State Management That Actually Makes Sense]]></title>
            <link>https://medium.com/@hari626007/lwc-state-explained-lwc-state-management-that-actually-makes-sense-69a80cb4ca23?source=rss-79f4c19c681b------2</link>
            <guid isPermaLink="false">https://medium.com/p/69a80cb4ca23</guid>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[lightning-web-component]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[lwc]]></category>
            <category><![CDATA[salesforce-lwc]]></category>
            <dc:creator><![CDATA[Hari Baskar S]]></dc:creator>
            <pubDate>Wed, 06 May 2026 19:17:36 GMT</pubDate>
            <atom:updated>2026-05-06T19:17:36.945Z</atom:updated>
            <content:encoded><![CDATA[<p>At some point every LWC developer has written an event handler whose only job is to pass a value one level up so another handler can pass it one level down. @lwc/state is Salesforce&#39;s answer to that specific kind of misery — and it&#39;s surprisingly clean. Before lwc/state we encountered issues in terms of:</p><ul><li>Reduced Prop Drilling on Child &amp; Grandchild Component</li><li>Reduces the need of custom events &amp; event handler to sync values &amp; mutate value.</li><li>Easy implementation of computed property which depends upon the main property being tracked.</li><li>Predictable data mutation &amp; sync across multiple components as everything happens from single place (explained why later)</li></ul><p>LWC State would be an overkill for components with just 2–3 child components. The main use case comes into the picture when you a lot of child components &amp; grandchild components each having their own properties to be passed down and change in a child/grandchild needs to be bubbled through all their parents &amp; grandparents. This is where lwc/state simplifies the process of syncing &amp; mutation of values dramatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cYa3Sffd4lWafqrzisU1EA.png" /></figure><p><strong>WORKING OF LWC STATES:</strong></p><p>First we will need to define a State Management Factory method which will be containing the below:</p><ul><li>Atoms</li><li>Computed Properties</li><li>Actions</li></ul><p><strong>Atoms</strong> are the individual properties that needs to be synced across multiple component. This atom can be anything. It can be a String, Number, Array, Object etc.</p><p><strong>Computed Properties </strong>are the properties which can be derived from the Atoms and will need to be re-calculated whenever the dependent atoms are mutated via a setAtom() call.</p><p><strong>Actions </strong>are methods which can be called on the state manager which can be used for having common logic that would be required based on requirement.</p><p>State Management has two main methods:</p><ul><li><strong>defineState():<br></strong>- This is used to define the state management factory method. <br>- This supports the atom(), setAtom() &amp; computed() methods inside it. These methods cannot be called outside the defineState().<br>- This is where we will be defining the Atoms, Computed properties &amp; Actions. <br>- It also takes in variable args which can be used to pass the initial values for the atoms.</li><li><strong>fromContext():<br></strong>- Once a state is initialised in a Parent Component and both the Child &amp; Parent Component are inserted into the DOM, the fromContext() helps getting the most relevant state defined and attached to the DOM from which we will be able to get access to the atoms, computed props &amp; actions.</li></ul><p>Inside the State Mgt factory method definition of the <strong>defineState</strong>, below methods are supported:</p><ul><li><strong>atom(initialValue):<br>- </strong>This can be used to initialise a new atom.<br>- It can also take in an initial value passed in the defineState which can be used to initialise the atom with.</li><li><strong>setAtom(atom, newValue):<br>- </strong>This can be used to update an atom which can be called in an action defined in the state which inturn can be called by any LWC importing the state. <br>- setAtom cannot be called directly outside the state definition.</li><li><strong>computed( […dependentAtoms] , (input) =&gt; {methodDefWithReturn} )<br>- </strong>This can be used for defining any property that depends upon the atoms. <br>- The input will be those values which are the dependent atoms. They can be access directly without <strong>.value</strong> notation. <br>- We can define all the atoms based on which this value is dependent on and when any of those atoms are mutated, then the computed() method will be called to update the computed value.</li></ul><p>So now coming to the Work Flow:</p><ul><li>We make use of the defineState() to define the State Mgt Factory Method where we will define the atom, computed properties &amp; action.</li><li>We will initialise the state in a LWC and pass down the required initial values to initialise the atom values.</li><li>Once initialised, we can get access of the atom’s value <br>- Within the state factory methods as <strong>atom.value <br>- </strong>In LWC via state as <strong>state.value.atom</strong></li><li>In other LWC, we can get access to the state using the fromContext() which will return the state from where we can access the atoms &amp; actions via the same notation of <strong>state.value.action()</strong> &amp; <strong>state.value.atom</strong></li><li>So any access to the required value will be happening via the state.value.atom which will making the values to be consistent across component.</li><li>Any changes that needs to be made on the atoms will be made via the exposed actions which will make use of the setAtom to update the atom which will be then reflected across all the places where the atoms are referenced.</li></ul><p>To sum it up, it becomes a central to place to retrieve &amp; mutate values thus maintaing consistency across components. Also as this is obtained via the state, there is no prop drilling required from parent to child components making it simpler &amp; cleaner.</p><p><strong>WORKING DEMO:</strong></p><p>I will try to implement a simple shopping cart for the demo which is a go to example in case of other state management libraries like redux.</p><ul><li><strong>Defining the State Management Factory Method:</strong></li></ul><p>We will be defining the State Factory method and exporting the method. Its better to do this in a separate LWC rather than a helper file.</p><pre>import { defineState } from &#39;@lwc/state&#39;;<br><br>export const cartStateManager = defineState(({ atom, computed, setAtom }, initialCartItems = []) =&gt; {<br>    // Declaring Atoms<br>    const cartItems = atom(initialCartItems);<br><br>    // Declaring Computed Properties<br>    const cartItemsCount = computed([cartItems], (cartItems) =&gt; {<br>        return cartItems.length;<br>    })<br><br>    const cartTotalValue = computed([cartItems], (items) =&gt; {<br>        console.log(`Compute being called: ${cartItems.value} and direct atom: ${cartItems}`);<br>        return items.reduce((price, item) =&gt; price += item.price * item.quantity, 0);<br>    })<br><br>    // State Actions <br>    const addItems = (item) =&gt; {<br>        setAtom(cartItems, [...cartItems.value, item]);<br>    }<br><br>    // Returns the required properties to be exposed publically<br>    return {<br>        cartItems,<br>        cartItemsCount,<br>        cartTotalValue,<br>        addItems<br>    };<br>})</pre><ul><li><strong>Initialise the state in a parent LWC.</strong></li></ul><p>For the demo this is my LWC structure:</p><pre>shoppingParent<br>  - cart<br>  - cartPrice</pre><p>So in my case I will have to initialise the state in shoppingParent:</p><p>JS:</p><pre>import { cartStateManager } from &#39;c/cartStateManager&#39;;<br>import { LightningElement } from &#39;lwc&#39;;<br><br>export default class ShoppingParent extends LightningElement {<br>    // Initialising the State<br>    cartState = cartStateManager();<br>}</pre><p>HTML:</p><pre>&lt;template&gt;<br>    &lt;c-cart&gt;&lt;/c-cart&gt;<br>    &lt;c-cart-price&gt;&lt;/c-cart-price&gt;<br>&lt;/template&gt;</pre><ul><li><strong>Import the state context using fromContext() in child LWC</strong></li></ul><p>Below would the code for cart LWC (child component):</p><p>JS:</p><p>It may look big but the main parts are:</p><ul><li>Getting the relevant State initialised in the parent via the <strong>fromContext()</strong></li><li>Making use of the state via the <strong>state.value.atom</strong> or <strong>state.value.action()</strong> format.</li></ul><p>Rest of them are just use case logic which doesnt matter.</p><pre>import {fromContext} from &#39;@lwc/state&#39;;<br>import { cartStateManager } from &#39;c/cartStateManager&#39;;<br>import { LightningElement } from &#39;lwc&#39;;<br><br>export default class Cart extends LightningElement {<br>    // Getting the relevant state initialised in parent LWC.<br>    cartState = fromContext(cartStateManager);<br><br>    itemHolder = this.initializeItemHolder();<br><br>    // Product list with price<br>    productOptions = [<br>        { label: &#39;Laptop&#39;, value: &#39;Laptop&#39;, price: 50000 },<br>        { label: &#39;Mobile&#39;, value: &#39;Mobile&#39;, price: 20000 },<br>        { label: &#39;Headphones&#39;, value: &#39;Headphones&#39;, price: 3000 }<br>    ];<br><br>    initializeItemHolder() {<br>        return {<br>            guid: this.generateGUID(),<br>            product: &#39;&#39;,<br>            quantity: 1<br>        };<br>    }<br><br>    handleChange(event) {<br>        const { name } = event.target.dataset;<br>        const fieldValue = event.detail?.value || event.target.value;<br><br>        if (name === &#39;product&#39;) {<br>            this.itemHolder.product = fieldValue;<br>        } else if (name === &#39;quantity&#39;) {<br>            this.itemHolder.quantity = parseInt(fieldValue, 10);<br>        }<br>    }<br><br>    handleAdd() {<br>        if (!this.itemHolder.product || !this.itemHolder.quantity) {<br>            return;<br>        }<br><br>        // Find selected product object<br>        const product = this.productOptions.find(<br>            p =&gt; p.value === this.itemHolder.product<br>        );<br><br>        const newItem = {<br>            guid: this.itemHolder.guid,<br>            product: this.itemHolder.product,<br>            price: product.price,<br>            quantity: this.itemHolder.quantity<br>        };<br><br>        // Calling the addItems defined on the state to sync the value across LWCs.<br>        this.cartState.value.addItems(newItem);<br><br>        // Reset item holder with new guid<br>        this.itemHolder = {<br>            guid: this.generateGUID(),<br>            product: &#39;&#39;,<br>            quantity: 1<br>        };<br>        console.log(`Current Cart State: ${JSON.stringify(this.cartState.value)}`);<br><br>    }<br><br>    generateGUID() {<br>        return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;<br>    }<br>}</pre><p>HTML:</p><pre>&lt;template&gt;<br>    &lt;lightning-card&gt;<br>        &lt;div class=&quot;slds-var-p-around_medium&quot;&gt;<br>            &lt;!-- Product Selection --&gt;<br>            &lt;lightning-combobox label=&quot;Select Product&quot; value={itemHolder.product} options={productOptions}<br>                data-name=&quot;product&quot; onchange={handleChange}&gt;<br>            &lt;/lightning-combobox&gt;<br>            &lt;!-- Quantity --&gt;<br>            &lt;lightning-input type=&quot;number&quot; label=&quot;Quantity&quot; value={itemHolder.quantity} data-name=&quot;quantity&quot;<br>                onchange={handleChange} min=&quot;1&quot;&gt;<br>            &lt;/lightning-input&gt;<br>            &lt;!-- Add Button --&gt;<br>            &lt;lightning-button label=&quot;Add to Cart&quot; variant=&quot;brand&quot; class=&quot;slds-var-m-top_small&quot; onclick={handleAdd}&gt;<br>            &lt;/lightning-button&gt;<br>        &lt;/div&gt;<br>        &lt;div class=&quot;slds-var-m-around_medium&quot;&gt;<br>            &lt;template for:each={cartState.value.cartItems} for:item=&quot;item&quot;&gt;<br>                &lt;div key={item.guid}&gt;<br>                    Id: {item.guid}<br>                    Name: {item.product}<br>                    Price: {item.price}<br>                    Quantity: {item.quantity}<br>                    Total Price: {item.quantity * item.price}<br>                &lt;/div&gt;<br>            &lt;/template&gt;<br>        &lt;/div&gt;<br>    &lt;/lightning-card&gt;<br>&lt;/template&gt;</pre><p>Similarly for the cart-price child LWC:</p><p>JS:</p><pre>import { cartStateManager } from &#39;c/cartStateManager&#39;;<br>import { LightningElement } from &#39;lwc&#39;;<br>import {fromContext} from &#39;@lwc/state&#39;;<br><br>export default class CartPrice extends LightningElement {<br>    cartState = fromContext(cartStateManager);<br>}</pre><p>HTML:</p><pre>&lt;template&gt;<br>    &lt;lightning-card title=&quot;Cart Summary&quot;&gt;<br>        &lt;div class=&quot;slds-var-m-around_medium&quot;&gt;<br>            Total items: {cartState.value.cartItemsCount}<br>            Total price: {cartState.value.cartTotalValue}<br>        &lt;/div&gt;<br>    &lt;/lightning-card&gt;<br>&lt;/template&gt;</pre><p><strong>VALIDATION &amp; WORKING:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r_TDz7Vbd3-0BsryKpeitA.png" /></figure><p>Above is our UI and in here when I try to add a product,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ApozpeYBA1qYs64_B5zFLw.png" /></figure><p>So what happens here is</p><ul><li>On clicking the <strong>Add to Cart</strong> button, the cart item is constructed and the addItems() on the state is called with the new item as the input.</li><li>This will in turn call the setAtom which will be updating the Atom with the new list.</li><li>The update of the list triggers the re-calculation of the computed properties which is then reflected in the Cart Summary Components.</li></ul><p>This is also then synced with the iterator defined on cart.html to iterate through the list of the cart elements.</p><p>So the properties &amp; methods exposed via the State acts as a single source of truth &amp; the single point of mutation which when implemented across components brings in the consistency.</p><p>The main highlight is in the child components, we didn&#39;t have to:</p><ul><li>Declare any public variables.</li><li>Add those public variables in the HTML declaration from parent.</li><li>No events &amp; event handler.</li></ul><p><strong>SOME OBSERVATION W.R.T LWC STATES:</strong></p><ul><li>In case of simple string, the direct mutation of the atom via the setAtom() method is fine. But when it comes to mutation of objects or array its better to do a <strong>Immutable Update</strong> i.e., clone (shallow copy) &amp; mutate rather than a in-place mutation. This because if you had to do it then you would be doing something similar to this:</li></ul><pre>cartItems.value.push(item);<br>setAtom(cartItems, cartItems.value); // This is actually possible now as of May 2026<br>// But the above approach is not recommended.</pre><p>Instead make use of the below approach:</p><pre>// Clone &amp; Mutate<br>setAtom(cartItems,[...cartItems.value,item]);</pre><p>This would be applicable for all List &amp; Object related operation. Below is a suggested list of alternatives for avoiding in-place mutation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U4VRT42SRtwRiGkk-9J8Qg.png" /></figure><p>For the same reason I would suggest avoiding the use of <strong>.forEach</strong> method on array for mutation as they also perform in-place mutation on the array and make use of <strong>.map </strong>instead which will return the list which can be then used with setAtom.</p><p><strong>SYNC BETWEEN IRRELEVANT LWC:</strong></p><p>In the intro I also mentioned about making use of LWC State even when they are not linked by a Parent-Child relationship.</p><p>This would be possible via the below approach:</p><ul><li>Define the State Factory Method.</li><li>Define an instance in the the Factory Method Definition file itself &amp; export.</li><li>In the required LWCs, import the instances (singleton approach) defined above.</li><li>Perform the required operations on the singleton.</li></ul><p>Because its a singleton, even if two LWC are not related at all, they are importing the same singleton because of which they will be in sync automatically.</p><p><strong>Code for the above approach:</strong></p><p>State Manager Factory Definition:</p><pre>import { defineState } from &#39;@lwc/state&#39;;<br><br>export const cartStateManager = defineState(({ atom, computed, setAtom }, initialCartItems = []) =&gt; {<br>  // Same method definition as above <br>})<br><br>// Singleton export<br>export const cartStateSingleton = cartStateManager();</pre><p>Now in the required LWC:</p><pre>import { LightningElement } from &#39;lwc&#39;;<br>import { cartStateSingleton } from &#39;c/cartStateManager&#39;;<br><br>export default class CartPrice extends LightningElement {<br>    cartState = cartStateSingleton;<br>}</pre><p>Now we have access to the singleton defined from where we can perform the required action with same syntax of <strong>state.value.atom or state.value.action() </strong>as mentioned above.</p><p><strong>VERY IMPORTANT NOTE/OBSERVATION:</strong></p><p>This avoids the needs of :</p><ul><li>Importing the State Factory Method.</li><li>fromContext()</li></ul><p>This in-turn allows to get access to the state values &amp; action before the components are completely inserted into DOM i.e., even before the connectedCallback() is completed. This is because fromContext will be able to get the relevant state from the parent only when both child &amp; parent are completely inserted into the DOM.</p><p><strong>OUTPUT VALIDATION:</strong></p><p>In my flexipage I have isolated those two components:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NaDN8Cw5EblDUP7p0m5KDw.png" /></figure><p>And by using the singleton in my required LWC:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N5g-qouvH4ue1BAAT6awPw.png" /></figure><p>But the issue would be then when a component’s state needs to be scoped to its parent and not a global level, this singleton approach fails. This is where I would suggest we can go with a mixed approach where:</p><ul><li>I will define the State Factory Method &amp; export it.</li><li>I will also initiailise the state and export it.</li></ul><p>In case of global page sync, I will make use of the singleton and for parent-scoped sync, I will make use of the fromContext() approach.</p><p><strong>NOTE: </strong>Even though its a singleton, the state sync is restricted to the components within the single browser tab. This cannot be used for syncing values across tabs.</p><p><strong>CONCLUSION:</strong></p><p>Hope I gave you some level understanding on this. For more detailed explanation I would recommend going through this Counter example given by Salesforce in their official docs: <a href="https://developer.salesforce.com/docs/platform/lwc/guide/state-management-define.html">LWC State Management Guide.</a></p><p>I have also uploaded my code into a git repo:</p><p>Below is the main branch which contains the approach of Parent-Child with fromContext to get the state.</p><p><a href="https://github.com/hari0409/medium-lwc-state-mgt/tree/main">GitHub - hari0409/medium-lwc-state-mgt</a></p><p>And the below one is the one for making use of singleton avoiding the fromContext.</p><p><a href="https://github.com/hari0409/medium-lwc-state-mgt/tree/singleton">GitHub - hari0409/medium-lwc-state-mgt at singleton</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69a80cb4ca23" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[FlowAttributeChangeEvent & @api Explained — Sync LWC Data with Salesforce Flow in Real Time]]></title>
            <link>https://medium.com/@hari626007/flowattributechangeevent-api-explained-sync-lwc-data-with-salesforce-flow-in-real-time-b0a1df42839b?source=rss-79f4c19c681b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0a1df42839b</guid>
            <category><![CDATA[lightning-web-component]]></category>
            <category><![CDATA[salesforce-flow]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[salesforce-lightning]]></category>
            <dc:creator><![CDATA[Hari Baskar S]]></dc:creator>
            <pubDate>Thu, 16 Apr 2026 20:17:33 GMT</pubDate>
            <atom:updated>2026-04-17T04:39:00.096Z</atom:updated>
            <content:encoded><![CDATA[<p>Lets say you have some public variables defined in your LWC, then when you make changes how do you sync them back with the Flow ?</p><p>This is what we are gonna see how to do and what kind of sync we can do based on each approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9DuID9Sw-p9yqG_oce6aWQ.png" /></figure><p><strong>USECASE FOR DEMONSTRATION:</strong></p><p>For the sake of the demonstration, I want to have a LWC which will be embedded in the Flow. This LWC will be collecting information from the User like Username, Age, Email and then go with further processing.</p><p>To handle the data, I went ahead and made use of Apex Types which was defined as below:</p><pre>public with sharing class UserData {<br>    @AuraEnabled public String username;<br>    @AuraEnabled public Integer age;<br>    @AuraEnabled public String email;<br>}</pre><p>With the help of the above I can:</p><ul><li>Make use of this as a Custom Data Type in Flow Variables</li><li>Make use of this as a Return Type for public variables in the LWC via the XML Config.</li></ul><p>This makes the accessibility of the property of the User Data object much easier.</p><p><strong>SYNC LWC-FLOW VALUES BETWEEN SCREEN:</strong></p><p>Lets say you have an LWC which is embedded in a Flow and you want the variables in the LWC to be:</p><ul><li>Accessible in the Flow</li><li>Change when the LWC changes the value</li><li>You want the change to be reflected between screens (Very Important Distinction, not within the same screen)</li></ul><p>Then we can just do the below:</p><ul><li>Declare the variable you want to sync with Flow as @api annotated.</li><li>Define the variable in your XML Configuration</li></ul><p>NOTE: We can also expose a private variable via a Getter &amp; Setter for the same which I cover later in this article.</p><p><strong>STEPS:</strong></p><ul><li>Define a public @api annotated variable in JS.</li></ul><pre>import { api, LightningElement } from &#39;lwc&#39;;<br><br>export default class ApiVariableSync extends LightningElement {<br>    @api userData = {};<br><br>    changeHandler(event) {<br>        let field = event.currentTarget.dataset.field;<br>        let value = event.currentTarget.value;<br><br>        this.userData = { ...this.userData, [field]: value };<br>    }<br>}</pre><p>Additionally, I have also defined a logic for getting the value from the User from the Screen</p><p>HTML:</p><pre>&lt;template&gt;<br>    &lt;lightning-input label=&quot;User Name&quot; value={userData.username} onchange={changeHandler} data-field=&quot;username&quot;&gt;&lt;/lightning-input&gt;<br>    &lt;lightning-input label=&quot;Age&quot; value={userData.age} onchange={changeHandler} data-field=&quot;age&quot; type=&quot;number&quot;&gt;&lt;/lightning-input&gt;<br>    &lt;lightning-input label=&quot;Email&quot; value={userData.email} onchange={changeHandler} data-field=&quot;email&quot;&gt;&lt;/lightning-input&gt;<br>&lt;/template&gt;</pre><ul><li>Now we have to define this userData public variable in the XML</li></ul><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;LightningComponentBundle xmlns=&quot;http://soap.sforce.com/2006/04/metadata&quot;&gt;<br>    &lt;apiVersion&gt;66.0&lt;/apiVersion&gt;<br>    &lt;isExposed&gt;true&lt;/isExposed&gt;<br>    &lt;targets&gt;<br>        &lt;target&gt;lightning__FlowScreen&lt;/target&gt; &lt;!-- To be made available in Flow --&gt;<br>    &lt;/targets&gt;<br>    &lt;targetConfigs&gt;<br>        &lt;targetConfig targets=&quot;lightning__FlowScreen&quot;&gt;<br>            &lt;!-- Public Variable defined with the Custom Apex Type --&gt;<br>            &lt;property label=&quot;User Data&quot; name=&quot;userData&quot; type=&quot;apex://UserData&quot;&gt;&lt;/property&gt;<br>        &lt;/targetConfig&gt;<br>    &lt;/targetConfigs&gt;<br>&lt;/LightningComponentBundle&gt;</pre><ul><li>Deploy the LWC and add it to a Screen Flow.</li></ul><p>NOTE: We also have an additional property called role defined which when given as:</p><ul><li>inputOnly =&gt; Can be used to set value from Flow</li><li>outputOnly =&gt; Can be used get value LWC</li></ul><p>But when the role is not given, then by default it can be used for both and for the sync between LWC &amp; Flow to work, we need it to be used for both input &amp; output because of which we will not give it a role.</p><p><strong>VALIDATION STEPS:</strong></p><p>Now we are ready to use the LWC in the Flow. We can just do so by:</p><ul><li>Create a Screen Flow &amp; embed the LWC:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LktjrWivwhCgJWLDcN48Pw.png" /></figure><ul><li>So, to validate the value we have, I have added one more screen which will be just displaying the entire resource of the lwc.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iV07zI93UcvkgMjXcdbjGA.png" /></figure><ul><li>Also because we made of Apex Define Type, we can make use of the individual property of the object too:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*B6YA_OU3uu8quFUqkfozYg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*g6RWLyd1g5YvjqZrTVhr-w.png" /></figure><p>So, now here I can access my required individual property and use it for further processing in the flow when required.</p><p>Now for the output:</p><p>On debugging the Flow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uUMtRH_WVS5q8HB0bfNLrQ.png" /></figure><p>And on clicking Next:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5mc-n9334QmEM3doyf26lQ.png" /></figure><p>So the whatever the value given over in the LWC, we are able to see it. And we are seeing it as an entire JSON because we choose the entire resource for the display text.</p><p><strong>SYNCING OF PRIVATE VARIABLES VIA EXPOSED GETTERS &amp; SETTERS:</strong></p><p>This can be also done by the same above approach but this gives a even more clear understanding on how values are read &amp; set. This can be done by:</p><ul><li>Defining a Private Variable</li><li>Expose the private variable via @api annotated getters &amp; setters.</li><li>Expose the public getter &amp; setter in the XML configuration similar to how variables are exposed.</li></ul><p><strong>STEPS:</strong></p><ul><li>Define private variables with public setters &amp; getters</li></ul><pre>export default class SampleFlowInteraction extends LightningElement {<br>    _userData = {};<br><br>    @api<br>    get userData() {<br>        console.log(`Getter called ${JSON.stringify(this._userData)} - ${Date.now()}`);<br><br>        return this._userData;<br>    }<br>    set userData(data) {<br>        console.log(`Setter called ${JSON.stringify(data)} - ${Date.now()}`);<br>        if (data != null) {<br>            this._userData = data;<br>        }<br>    }<br><br>    changeHandler(event) {<br>        let field = event.currentTarget.dataset.field;<br>        let value = event.currentTarget.value;<br><br>        this._userData = { ...this._userData, [field]: value };<br>    }<br>}</pre><p>HTML:</p><pre>&lt;template&gt;<br>    &lt;lightning-input label=&quot;User Name&quot; value={_userData.username} onchange={changeHandler} data-field=&quot;username&quot;&gt;&lt;/lightning-input&gt;<br>    &lt;lightning-input label=&quot;Age&quot; value={_userData.age} onchange={changeHandler} data-field=&quot;age&quot; type=&quot;number&quot;&gt;&lt;/lightning-input&gt;<br>    &lt;lightning-input label=&quot;Email&quot; value={_userData.email} onchange={changeHandler} data-field=&quot;email&quot;&gt;&lt;/lightning-input&gt;<br>&lt;/template&gt;</pre><ul><li>Expose it via the XML for the Flow Screen:</li></ul><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;LightningComponentBundle xmlns=&quot;http://soap.sforce.com/2006/04/metadata&quot;&gt;<br>    &lt;apiVersion&gt;66.0&lt;/apiVersion&gt;<br>    &lt;isExposed&gt;true&lt;/isExposed&gt;<br>    &lt;targets&gt;<br>        &lt;target&gt;lightning__FlowScreen&lt;/target&gt;<br>    &lt;/targets&gt;<br>    &lt;targetConfigs&gt;<br>        &lt;targetConfig targets=&quot;lightning__FlowScreen&quot;&gt;<br>            &lt;property label=&quot;User Data&quot; name=&quot;userData&quot; type=&quot;apex://UserData&quot;&gt;&lt;/property&gt;<br>        &lt;/targetConfig&gt;<br>    &lt;/targetConfigs&gt;<br>&lt;/LightningComponentBundle&gt;</pre><ul><li>Now on embedding the LWC in the Flow:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RQxVE42LWMZOxdATT-w3yw.png" /></figure><p>And to validate, like before I have just added a display text of the entire resource:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TP1esqK-VOogu3yqdEm1HA.png" /></figure><p><strong>VALIDATION STEPS:</strong></p><p>On Debugging the above flow,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4CKzXJ42EZt5hdtaPcotSg.png" /></figure><p>And on clicking the Next, values are read and stored in the Flow’s Context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BvXqKmGBP27QGrM8ciFZw.png" /></figure><p>And now on clicking the Previous button, the values are loaded into the LWC from the Flows Context syncing the values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mu3Q5WR98AwI04SmUycVyA.png" /></figure><p><strong>WORKING:</strong></p><ul><li>We are exposing the variable/getter-setter by making it @api decorated and also via the XML so that the public variable is accessible to the Flow.</li><li>In the LWC, we are constructing the data and when we click the Next Button, the FlowNavigationNextEvent will be fired which will <strong>read all the exposed property or via the getter</strong> of the LWC and store it in the flow context. This can be used in the Flow for further processing.</li><li>On clicking on the Previous Button (lets say your going back), the LWC is loaded again during which the variable store in the Flow Context is <strong>loaded into the LWC or via the setter</strong> thus making it sync on coming back to the previous screen.</li></ul><p><strong>SUMMARY:</strong></p><p>NextEvent =&gt; Getter called =&gt; PreviousEvent =&gt; Setter Called.</p><p>By means of the above, the flow will be able to sync the variables between screen.</p><p>NOTE: For the persistence on back navigation to work, we must make sure the LWC Advanced Configuration is made as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G1GnOOLslykyaNaU-Bnidw.png" /></figure><p><strong>SYNC LWC-FLOW VARIABLES WITHIN A SCREEN:</strong></p><p>This is what can be used to bring true reactivity between Flow &amp; LWC. This is particularly useful when there is a Flow Screen with:</p><ul><li>LWC embedded</li><li>Other Flow Screen Components within the same screen component.</li></ul><p>Now when you want the Screen Component to behave based on the output from the LWC, this approach can be used. This can be done by:</p><ul><li>Declare the required variables with @api annotation or a private variable with public (@api annotated) getters &amp; setters.</li><li>This public variables or public setters &amp; getters are then also exposed via the XML for it to be accessible for the Flow.</li><li>Now whenever the LWC is ready with the data, we can just dispatch an event called the <strong>FlowAttributeChangeEvent </strong>with the required data.</li><li>This makes the updated data available in the flow based on which we can perform the other required processing inside the Flow.</li></ul><p><strong>STEPS:</strong></p><ul><li>Declaring a public variable &amp; also adding code for dispatching the FlowAttributeChangeEvent based on submit (In my case, can be different for you based on your use case)</li></ul><pre>import { api, LightningElement } from &#39;lwc&#39;;<br>import { FlowAttributeChangeEvent } from &#39;lightning/flowSupport&#39;;<br><br>export default class ApiVariableSync extends LightningElement {<br>    @api userData = {};<br><br>    changeHandler(event) {<br>        let field = event.currentTarget.dataset.field;<br>        let value = event.currentTarget.value;<br>        this.userData = { ...this.userData, [field]: value };<br>    }<br><br>    submitHandler() {<br>        this.dispatchEvent(new FlowAttributeChangeEvent(&quot;userData&quot;, this.userData));<br>    }<br>}</pre><p>HTML:</p><pre>&lt;template&gt;<br>    &lt;lightning-input label=&quot;User Name&quot; value={userData.username} onchange={changeHandler} data-field=&quot;username&quot;&gt;&lt;/lightning-input&gt;<br>    &lt;lightning-input label=&quot;Age&quot; value={userData.age} onchange={changeHandler} data-field=&quot;age&quot; type=&quot;number&quot;&gt;&lt;/lightning-input&gt;<br>    &lt;lightning-input label=&quot;Email&quot; value={userData.email} onchange={changeHandler} data-field=&quot;email&quot;&gt;&lt;/lightning-input&gt;<br>    &lt;div&gt;<br>        &lt;lightning-button label=&quot;Submit to Flow&quot; onclick={submitHandler}&gt;&lt;/lightning-button&gt;<br>    &lt;/div&gt;<br>&lt;/template&gt;</pre><p>XML:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;LightningComponentBundle xmlns=&quot;http://soap.sforce.com/2006/04/metadata&quot;&gt;<br>    &lt;apiVersion&gt;66.0&lt;/apiVersion&gt;<br>    &lt;isExposed&gt;true&lt;/isExposed&gt;<br>    &lt;targets&gt;<br>        &lt;target&gt;lightning__FlowScreen&lt;/target&gt;<br>    &lt;/targets&gt;<br>    &lt;targetConfigs&gt;<br>        &lt;targetConfig targets=&quot;lightning__FlowScreen&quot;&gt;<br>            &lt;property label=&quot;User Data&quot; name=&quot;userData&quot; type=&quot;apex://UserData&quot;&gt;&lt;/property&gt;<br>        &lt;/targetConfig&gt;<br>    &lt;/targetConfigs&gt;<br>&lt;/LightningComponentBundle&gt;</pre><p>Thats it. Now we can just add the LWC to the Flow and can define logic based on the data from the LWC for changes that required within the same screen.</p><p><strong>VALIDATION STEPS:</strong></p><ul><li>Adding the LWC to the Flow and adding a visibility condition based on the LWC Data</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lDNOucLNSg1Yf3nQJ9d79Q.png" /></figure><ul><li>Adding an another screen with the Entire Resource of the LWC to display all the captured data:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*onTiNeQPzzCNbc3lZBVOuw.png" /></figure><ul><li>So now on debugging it:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yjasqYmQGWFZoESdpg69lg.png" /></figure><p>Here I give the data which will not trigger the visibility condition on submit. But then when I give the data to satisify the condition and then submit it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ipZWcew0F9acElyg6tanSQ.png" /></figure><p>In my code am dispatching the event only on submit but based on your use case you can also dispatch the event on changeHandler too so that it will be even more reactive i.e., user doesnt have to click on a button to trigger the event to observe the change.</p><ul><li>Now on going to the next screen:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hy5PL1BxxqpehbmrCmTSJQ.png" /></figure><ul><li>And on going back:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_FeBygxR544tYmJsudU_9g.png" /></figure><p>The data is loaded back as it was before the Next button was clicked. This shows that there is persistence in the data again while moving back and forth in the Flow.</p><p>This works in the same way when we have a private variable exposed via a public getter-setter which can be implemented like below:</p><pre>import { api, LightningElement } from &#39;lwc&#39;;<br>import { FlowAttributeChangeEvent } from &#39;lightning/flowSupport&#39;;<br><br>export default class ApiVariableSync extends LightningElement {<br>    _userData = {};<br><br>    @api<br>    get userData() {<br>        console.log(&#39;Called Getter&#39;);<br><br>        return this._userData;<br>    }<br>    set userData(data) {<br>        if (data != null) {<br>            console.log(`Called Setter with ${JSON.stringify(data)}`);<br>            this._userData = data;<br>        }<br>    }<br><br>    changeHandler(event) {<br>        let field = event.currentTarget.dataset.field;<br>        let value = event.currentTarget.value;<br>        this._userData = { ...this._userData, [field]: value };<br>    }<br><br>    submitHandler() {<br>        console.log(`Dispatch FlowAttributeChangeEvent with ${JSON.stringify(data)}`);<br>        <br>        this.dispatchEvent(new FlowAttributeChangeEvent(&quot;userData&quot;, this._userData));<br>    }<br>}</pre><p><strong>WORKING:</strong></p><ul><li>So we have the exposed variable/getter-setter and when the FlowAttributeChangeEvent is fired, the data is sent to the Flow via the event i.e., <strong>this.dispatchEvent(new FlowAttributeChangeEvent(‘propertyName’,data))</strong></li><li>This data sent via the event is the source of truth for the flow and the flow tries to sync it back to LWC with this emitted data by assigning this value or calls a setter.</li><li>The value obtained from the LWC is then used for its own computation. And because of the setter, the value between the LWC &amp; Flow is in sync. It doesn&#39;t matter what was in the LWC before the event because after the event, setter will override with the value from the event.</li><li>Along with the Getters &amp; Setter being called on Navigation events as mentioned above continuous to work.</li></ul><p><strong>VALIDATION OF WORKING:</strong></p><ul><li>On click of the Submit, the event is patched and after that the setter is called with the exact data sent via the event.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9131dXfnyxnLYoYX0bkh4A.png" /></figure><ul><li>This setter syncs the value from Flow to LWC.</li><li>And as usual, navigation events also trigger the getters &amp; setter based on what it may be. Setter for Previous &amp; Getter for Next.</li></ul><p>Below is for calling Next:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mz9vFR-UAyxDfZSI5D_qFQ.png" /></figure><p>Below is for calling Previous:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pxs1zTipEgxuOHxGJAsRRw.png" /></figure><p><strong>SUMMARY:</strong></p><p>FlowAttributeChangeEvent =&gt; Value updated in Flow Context =&gt; Setters Called =&gt; Value synced from LWC to Flow</p><p>This provides complete reactivity between the Flow &amp; LWC within the single screen.</p><p><strong>CONCLUSION:</strong></p><p>LWC and Flow synchronisation is not automatic — it follows clearly defined lifecycle hooks.</p><p><strong>@api &amp; XML</strong> =&gt; Between Screen reactivity &amp; persistence</p><p><strong>@api, XML &amp; FlowAttributeChangeEvent</strong> =&gt; Within Screen reactivity &amp; persistence. Automatically also provide between screen reactivity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0a1df42839b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reduce DML Statements with Multi sObject Types in Apex]]></title>
            <link>https://medium.com/@hari626007/reduce-dml-statements-with-multi-sobject-types-in-apex-670967a7b8c8?source=rss-79f4c19c681b------2</link>
            <guid isPermaLink="false">https://medium.com/p/670967a7b8c8</guid>
            <category><![CDATA[salesforce-apex]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[governor-limit]]></category>
            <category><![CDATA[salesforce-tools]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <dc:creator><![CDATA[Hari Baskar S]]></dc:creator>
            <pubDate>Sun, 05 Apr 2026 14:38:42 GMT</pubDate>
            <atom:updated>2026-04-05T14:38:42.929Z</atom:updated>
            <content:encoded><![CDATA[<p>You have 150 of it in a single transaction (Sync or Async) and you have to be careful with it. This article is one such tip which can help you reduce your DML usage in a transaction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XAfm5PlYHhmGxaR72aj99A.png" /></figure><p><strong>SIMPLE SCENARIO:</strong></p><p>Lets say you have 3 sObjects to be inserted into the DB. The basic approach would be to:</p><ul><li>Create a List&lt;sObject&gt; for each sObject</li><li>Perform DML on each List&lt;sObject&gt;</li></ul><p>Ultimately you will be consuming 3 DML statements. But what if I said we can insert all three records with 1 DML ?</p><p>Thats where <strong>DML on Multi SObject</strong> comes into picture. As all the Objects, Custom or Standard comes under this single category <strong>sObject </strong>, I can push all my records into that single List&lt;sObject&gt; &amp; perform the DML on it thus saving the DML required for other sObjects.</p><p><strong>IMPLEMENTATION CODE:</strong></p><pre>List&lt;sObject&gt; recordToInsert = new List&lt;sObject&gt;();<br>for (Integer i = 0; i &lt; 500; i++) {<br>    Account acc = new Account();<br>    acc.Name = &#39;Sample Account &#39; + String.valueOf(i);<br>    acc.Account_Ext_Id__c = UUID.randomUUID().toString();<br>    recordToInsert.add(acc);<br>}<br>for (Integer i = 0; i &lt; 500; i++) {<br>    Case newCase = new Case();<br>    newCase.Status = &#39;New&#39;;<br>    newCase.Origin = &#39;Web&#39;;<br>    newCase.Subject = &#39;Sample Subject &#39; + String.valueOf(i);<br>    recordToInsert.add(newCase);<br>}<br><br>for (Integer i = 0; i &lt; 500; i++) {<br>    Contact con = new Contact();<br>    con.LastName = &#39;New Contact &#39; + String.valueOf(i);<br>    recordToInsert.add(con);<br>}<br><br>insert recordToInsert; // DML on all three objects in one go</pre><p>So here am inserting 1500 records and ideally it would have taken me 3 DML but now based on the above code, it takes me only 1 DML to insert all 1500 records across multiple sObject types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*17FhM3nQdAJkF0jzF-XIXA.png" /></figure><p><strong>THINGS TO KNOW:</strong></p><p>Is that it ? Can you insert record left &amp; right using this method ? NOPE. It also comes it with its own set of limitation as usual with Salesforce.</p><p><strong>INSERTION ORDER:</strong></p><ul><li>Records are inserted in the same order that they are present in the list.</li><li>So in case of Parent-Child Records, Parent records needs to pushed first into the list then the Child records.</li></ul><p><strong>CHUNKING IN MULTI SOBJECT TYPE DML:</strong></p><p>When performing Multi sObject Type DML, chunking happens on the given list of records. i.e., the list will be broken into smaller chunks of records of the same sObject Type.</p><ul><li>Data is committed on a Chunk-by-Chunk basis and so are the Apex Trigger i.e, they get executed for each Chunk.</li><li>There can be at max only 10 chunks per operations. So we have to re-arrange our data to group sObjects together.</li><li>But even after re-arrangement, each chunk can at max have 200 records (to be considered for trigger) because of which 10 chunks * 200 records per chunk = 2000 records i.e., there can be only <strong>2000 records</strong> processed per DML operation when operating on a Multi SObject Type.</li></ul><p>Salesforce Official Documents explains chunking with example in here <a href="https://developer.salesforce.com/docs/atlas.en-us.260.0.api.meta/api/sforce_api_calls_create.htm#MixedSaveTitle">Creating Records for Different Object Types</a></p><p>For example the below piece of code too many chunks because it just keeps switching between the two objects thus throwing an error:</p><pre>List&lt;SObject&gt; recordsToInsert = new List&lt;SObject&gt;();<br>for (Integer i = 0; i &lt; 50; i++) {<br>    Account acc = new Account();<br>    acc.Name = &#39;Sample Account &#39;+String.valueOf(i);<br>    acc.Account_Ext_Id__c = UUID.randomUUID().toString();<br>    recordsToInsert.add(acc);<br><br>    Contact con = new Contact();<br>    con.LastName = &#39;Sample Contact &#39;+String.valueOf(i);<br>    con.Account = acc;<br>    recordsToInsert.add(con);<br>}<br>insert recordsToInsert;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q2HrLjv2WegiL_6xxd8suw.png" /></figure><p>Also here is a piece of code I used to validate the 2000 records per operation limit:</p><pre>List&lt;sObject&gt; recordToInsert = new List&lt;sObject&gt;();<br>for (Integer i = 0; i &lt; 1000; i++) {<br>    Account acc = new Account();<br>    acc.Name = &#39;Sample Account &#39; + String.valueOf(i);<br>    acc.Account_Ext_Id__c = UUID.randomUUID().toString();<br>    recordToInsert.add(acc);<br>}<br>for (Integer i = 0; i &lt; 1000; i++) {<br>    Case newCase = new Case();<br>    newCase.Status = &#39;New&#39;;<br>    newCase.Origin = &#39;Web&#39;;<br>    newCase.Subject = &#39;Sample Subject &#39; + String.valueOf(i);<br>    recordToInsert.add(newCase);<br>}<br><br>for (Integer i = 0; i &lt; 1000; i++) {<br>    Contact con = new Contact();<br>    con.LastName = &#39;New Contact &#39; + String.valueOf(i);<br>    recordToInsert.add(con);<br>}<br><br>insert recordToInsert;</pre><p>So here 3000 records in one DML and on executing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O7kdBVn4iofSDQVEA5s8ew.png" /></figure><p>This is because we chunk every 200 records. So on second for loop itself we reached the 10th Chunk.</p><p>And when I reduce it to 2000, it works with no issue:</p><pre>List&lt;sObject&gt; recordToInsert = new List&lt;sObject&gt;();<br>for (Integer i = 0; i &lt; 1000; i++) {<br>    Account acc = new Account();<br>    acc.Name = &#39;Sample Account &#39; + String.valueOf(i);<br>    acc.Account_Ext_Id__c = UUID.randomUUID().toString();<br>    recordToInsert.add(acc);<br>}<br>for (Integer i = 0; i &lt; 1000; i++) {<br>    Case newCase = new Case();<br>    newCase.Status = &#39;New&#39;;<br>    newCase.Origin = &#39;Web&#39;;<br>    newCase.Subject = &#39;Sample Subject &#39; + String.valueOf(i);<br>    recordToInsert.add(newCase);<br>}<br><br>insert recordToInsert;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SZi37FIwJAQyZHVsLJKemQ.png" /></figure><p>So at max <strong>10 CHUNKS</strong>. So order your data better. This is very important to be understood while working with Multi Object Type DML.</p><p><strong>SETUP vs NON-SETUP OBJECTS:</strong></p><ul><li>We cannot perform Multi Object Type DML on Setup related Objects except in case of:<br>- Custom Settings Records<br>- Group Records<br>- Group Membership Records<br>- Users (without UserRoleId)</li></ul><p><strong>HANDLING PARENT-CHILD &amp; SELF-LOOKUP REFERENCE BASED OPERATIONS:</strong></p><p><strong>PARENT-CHILD RELATIONSHIP:</strong></p><p>Parent Child Relationship records can also be pushed while creating a relationship between the two with the help of an <strong>External Id</strong> . So we have to create a <strong>Custom External Id field</strong> on the Parent object using which the lookup will be created.</p><p>Below code depicting the same:</p><pre>List&lt;SObject&gt; recordsToInsert = new List&lt;SObject&gt;();<br>List&lt;Account&gt; accountsToCreate = new List&lt;Account&gt;();<br>for (Integer i = 0; i &lt; 10; i++) {<br>    Account acc = new Account();<br>    acc.Name = &#39;Account Name &#39; + String.valueOf(i);<br>    acc.Account_Ext_Id__c = UUID.randomUUID().toString();<br>    accountsToCreate.add(acc);<br>}<br>recordsToInsert.addAll(accountsToCreate);<br><br>List&lt;Contact&gt; contactsToCreate = new List&lt;Contact&gt;();<br>for (Integer i = 0; i &lt; 10; i++) {<br>    Contact contact = new Contact();<br>    contact.LastName = &#39;Contact for&#39; + accountsToCreate[i].Name + &#39; &#39; + String.valueOf(i);<br>    Account acc = new Account();<br>    acc.Account_Ext_Id__c = accountsToCreate[i].Account_Ext_Id__c;<br>    contact.Account = acc;<br>    contactsToCreate.add(contact);<br>}<br>recordsToInsert.addAll(contactsToCreate);<br><br>insert recordsToInsert;</pre><p>So in here, acc.Account_Ext_Id__c = UUID.randomUUID().toString(); is used to create an External ID for the Parent record (Account) and the same is being referenced while creating the contact:</p><pre>Account acc = new Account();<br>acc.Account_Ext_Id__c = accountsToCreate[i].Account_Ext_Id__c;<br>contact.Account = acc;</pre><p>This process of creating a new Account() object and then assigning it to the field is required and it <strong>cant</strong> be done as below:</p><pre>contact.Account.Account_Ext_Id__c = accountsToCreate[i].Account_Ext_Id__c;</pre><p>This is because in the above case Account would be empty and thus accessing in the above manner would cause an <strong>Null Pointer Exception </strong>on execution.</p><p><strong>SELF-LOOKUP REFERENCES:</strong></p><p>We cannot have a record which references another records of the same sObject Type in the same call.</p><p>For example lets say we have a Parent Account &amp; a Child Account refers to the Parent Account. Then the insertion of the both Parent &amp; Child cannot happen on the same call unless its already present in the org and we are performing an upsert DML operation.</p><p>Even if you change your perspective of it being a Self-Lookup to being a Parent-Child in which case you can create an External Id on the object and make use of it to refer and insert all the data together like below:</p><pre>List&lt;SObject&gt; recordsToInsert = new List&lt;SObject&gt;();<br>List&lt;Account&gt; parentAccounts = new List&lt;Account&gt;();<br>for (Integer i = 0; i &lt; 10; i++) {<br>    Account acc = new Account();<br>    acc.Name = &#39;Parent Account &#39; + String.valueOf(i);<br>    acc.Account_Ext_Id__c = UUID.randomUUID().toString();<br>    parentAccounts.add(acc);<br>}<br>recordsToInsert.addAll(parentAccounts);<br><br>List&lt;Account&gt; childAccounts = new List&lt;Account&gt;();<br>for (Integer i = 0; i &lt; 10; i++) {<br>    Account acc = new Account();<br>    acc.Name = &#39;Child Account &#39; + String.valueOf(i);<br>    acc.Account_Ext_Id__c = UUID.randomUUID().toString();<br>    acc.Parent_Account__r = new Account(Account_Ext_Id__c = parentAccounts[i].Account_Ext_Id__c);<br>    childAccounts.add(acc);<br>}<br>recordsToInsert.addAll(childAccounts);<br>insert recordsToInsert;</pre><p>Then you will get the below error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LwBjbMdBObxKsQ7sP0mT2g.png" /></figure><p>This is Data is committed chunk by chunk. So as both parent &amp; child are present in the chunk, the parent is not yet committed and thus the child cannot refer to the parent.</p><p><strong>NOTE:</strong></p><ul><li>In case of Standard Lookup, Id will be usually stored in field like AccountId &amp; the reference to Account itself will be present as Account.</li><li>In case of Custom Loopup, Id will be present as Custom_Lookup__c while the reference to the record will be present as Custom_Lookup__r which is what you see about when making use of Ext Id to perform self-lookup relationship.</li></ul><p>So ideally, we can solve this issue by introducing a dummy object between the Parent &amp; Child thus breaking the Chunk and thus allowing us to insert both Parent &amp; Child in the same operation. This will look something similar to this:</p><pre>List&lt;SObject&gt; recordsToInsert = new List&lt;SObject&gt;();<br>List&lt;Account&gt; parentAccounts = new List&lt;Account&gt;();<br>for (Integer i = 0; i &lt; 10; i++) {<br>    Account acc = new Account();<br>    acc.Name = &#39;Parent Account &#39; + String.valueOf(i);<br>    acc.Account_Ext_Id__c = UUID.randomUUID().toString();<br>    parentAccounts.add(acc);<br>}<br>recordsToInsert.addAll(parentAccounts);<br>// Dummy Chunk Breaker object (With Auto-Number so not even Name is required.)<br>recordsToInsert.add(new Dummy_Chunk_Breaker__c());<br><br>List&lt;Account&gt; childAccounts = new List&lt;Account&gt;();<br>for (Integer i = 0; i &lt; 10; i++) {<br>    Account acc = new Account();<br>    acc.Name = &#39;Child Account &#39; + String.valueOf(i);<br>    acc.Account_Ext_Id__c = UUID.randomUUID().toString();<br>    acc.Parent_Account__r = new Account(Account_Ext_Id__c = parentAccounts[i].Account_Ext_Id__c);<br>    childAccounts.add(acc);<br>}<br>recordsToInsert.addAll(childAccounts);<br>insert recordsToInsert;</pre><p>And this will succeed (10 Parent, 10 Child, 1 Chunk Breaker). But its not just worth creating a Custom Object for it. Just do it as two different operations at this point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UYZKjZZzy9lXuCoXeHbpUA.png" /></figure><p><strong>CONCLUSION:</strong></p><p>I hope above information helps you at some point while you are debugging limit issues. Its quite interesting how a simple concept in OOPS like <strong>polymorphism</strong> — specifically inheritance helps you do this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=670967a7b8c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your Agentforce Agent Can Now Show a Form — Custom Input UI with Lightning Types]]></title>
            <link>https://medium.com/@hari626007/your-agentforce-agent-can-now-show-a-form-custom-input-ui-with-lightning-types-c360fa08a96d?source=rss-79f4c19c681b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c360fa08a96d</guid>
            <category><![CDATA[salesforce-agentforce]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[agentforce]]></category>
            <category><![CDATA[agentforce-platform]]></category>
            <dc:creator><![CDATA[Hari Baskar S]]></dc:creator>
            <pubDate>Sun, 29 Mar 2026 20:13:16 GMT</pubDate>
            <atom:updated>2026-03-29T20:15:52.833Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>This story is actually a continuation of my previous story:</p><p><a href="https://medium.com/@hari626007/how-to-use-lightning-types-to-build-custom-ui-for-agent-responses-fa284dca5382">How to Use Lightning Types to Build Custom UI for Agent Responses</a></p><p>So in the above story, we saw how we can make use of Lightning Types to display an output from an Agent Action to the User in the Agentforce Interface. Continuing on that, we will now see how we can make use of Lightning Types to get input from the User for an Agent Action.</p><p>This also works on the fundamental concept explain in my above article where the Agent will un-wrap the Input/Output of the Agent Action and if those Input/Output are a List&lt;Primitive_Objects&gt; or List&lt;Simple_CustomWrapper&gt; then on un-wrapping them, we will get Primitive Data Types for which Lightning Types cannot be overridden.</p><p>More detailed explanation in the above blog.</p><p>So, by applying the same principle over here, for gather a input we need a <strong>Custom Nested Wrapper </strong>and the associated set of LWC, Lightning Type, Agent Actions for it to work properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZfFWJeORoov1ZcsjD3PPaw.png" /></figure><p><strong>IMPLEMENTATION:</strong></p><p>Am taking a simple use-case of creating a Case using Agentforce. So for it I will:</p><ul><li>Define an Apex Action to create the Case</li><li>Agentforce Agent, Topic &amp; Action Definition</li><li>LWC for gathering input</li></ul><p><strong>Apex Class Definition:</strong></p><pre>public with sharing class CreateSupportCase {<br>    @InvocableMethod(label = &#39;Create Support Case&#39; description = &#39;This can be used to create a support case when asked by the user&#39;)<br>    public static List&lt;CaseOutputWrapper&gt; createSupportCase(List&lt;CaseInputWrapper&gt; caseInputWrapper){<br>        List&lt;CaseDetails&gt; caseDetails = new List&lt;CaseDetails&gt;();<br>        for (CaseInputWrapper inputWrapper : caseInputWrapper) {<br>            caseDetails.add(inputWrapper.caseDetails);<br>        }<br>        <br>        List&lt;Case&gt; casesToCreate = new List&lt;Case&gt;();<br>        for (CaseDetails detail : caseDetails) {<br>            Case newCase = new Case();<br>            newCase.Subject = detail.caseSubject;<br>            newCase.Description = detail.caseDescription;<br>            newCase.Priority = detail.priority;<br>            newCase.Status = &#39;New&#39;;<br>            newCase.Origin = &#39;Agent&#39;;<br>            casesToCreate.add(newCase);<br>        }<br>        insert as system casesToCreate;<br>        List&lt;CaseOutputWrapper&gt; output = new List&lt;CaseOutputWrapper&gt;();<br>        for (Case createdCase : casesToCreate) {<br>            CaseOutputWrapper outputWrapper = new CaseOutputWrapper();<br>            CaseOutputDetails detail = new CaseOutputDetails();<br>            detail.caseDescription = createdCase.Description;<br>            detail.caseSubject = createdCase.Subject;<br>            detail.priority = createdCase.Priority;<br>            detail.caseId = createdCase.Id;<br>            outputWrapper.caseOutputDetails = detail;<br>            output.add(outputWrapper);<br>        }<br>        return output;<br>    }<br>    <br>    public class CaseInputWrapper{<br>        @InvocableVariable(label = &#39;Case Input Wrapper&#39;) public CaseDetails caseDetails;<br>    }<br>    <br>    public class CaseOutputWrapper{<br>        @InvocableVariable(label = &#39;Created Cases&#39;) public CaseOutputDetails caseOutputDetails;<br>    }<br>    <br>    public class CaseOutputDetails{<br>        public String caseId;<br>        public String caseSubject;<br>        public String caseDescription;<br>        public String priority;<br>    }<br>    <br>    public class CaseDetails{<br>        public String caseSubject;<br>        public String caseDescription;<br>        public String priority;<br>    }<br>}</pre><p>The above code is just a simple logic to create cases via an Invocable Method with a Custom Nested Wrapper for both Input &amp; Output. For gathering input via Lightning Types, the Nested Wrapper is required for Input but I am just making it future proof in case I want to display the data also with an Custom UI.</p><p><strong>LWC for Custom Input Interface:</strong></p><p>Here also we have to make use of <strong>@api </strong>decorated <strong>getter &amp; setter for value()</strong> allowing the Agent to populate the value &amp; also to retrieve them.</p><p>These getters &amp; setters will be populating an internal LWC property which will be used for collection of data from the User. But apart from that, we will have a new addition which will an <strong>event</strong>.</p><p>So whenever we are making a change or whenever we are done with the change, we can <strong>dispatch an event</strong> called <strong>valuechange </strong>event which will contain the data which will be then used by the Agent for calling the Agent Action.</p><p>This event dispatch is just used to <strong>inform the agent</strong> about the current data present in the LWC thus keeping it <strong>in sync </strong>so that when the User clicks on Submit (provided by Agentforce) , it has the most recent data to pass to the Agent Action.</p><p>Agentforce will also display a <strong>Submit </strong>button not present as part of our LWC) in the Chat Interface, clicking on it will determine the completion of Input Gather and to proceed with the Action Execution. So this event is only for informing the agent about the current status of the data.</p><p>And at last, for the XML configuration, we need to make the target as <strong>lightning__AgentforceInput </strong>which allows us to create Lightning Types of Editor Config.</p><p>So the summary is:</p><ul><li>@api decorated getter &amp; setter for value()</li><li><strong>valuechange</strong> event to send the data to Agent</li><li>Target must include <strong>lightning__AgentforceInput</strong></li></ul><p>HTML:</p><pre>&lt;template&gt;<br>    &lt;lightning-card title=&quot;Raise a Support Case&quot;&gt;<br>        &lt;lightning-input data-field=&quot;caseSubject&quot; value={caseInformation.caseSubject} onchange={handleChange} label=&quot;Subject&quot;&gt;&lt;/lightning-input&gt;<br>        &lt;lightning-input data-field=&quot;caseDescription&quot; value={caseInformation.caseDescription} onchange={handleChange} label=&quot;Description&quot;&gt;&lt;/lightning-input&gt;<br>        &lt;lightning-combobox data-field=&quot;priority&quot; value={caseInformation.priority} options={priorityOptions} onchange={handleChange} label=&quot;Priority&quot;&gt;&lt;/lightning-combobox&gt;<br>    &lt;/lightning-card&gt;    <br>&lt;/template&gt;</pre><p>JS:</p><pre>import { api, LightningElement } from &#39;lwc&#39;;<br><br>export default class CreateCaseViaAgent extends LightningElement {<br>    caseInformation = {};<br><br>    @api<br>    get value() {<br>        return this.caseInformation;<br>    }<br>    set value(data) {<br>        if (data) {<br>            this.caseInformation = data;<br>        }<br>    }<br><br>    get priorityOptions() {<br>        return [<br>            { label: &quot;High&quot;, value: &quot;High&quot; },<br>            { label: &quot;Medium&quot;, value: &quot;Medium&quot; },<br>            { label: &quot;Low&quot;, value: &quot;Low&quot; },<br>        ]<br>    }<br><br>    handleChange(event) {<br>        let field = event.currentTarget.dataset.field;<br>        let value = event.currentTarget.value;<br>        // Constructing the data based on dataset defined on HTML<br>        this.caseInformation = { ...this.caseInformation, [field]: value };<br>        this.dispatchEvent(new CustomEvent(&quot;valuechange&quot;, {<br>            detail: { value: this.caseInformation },<br>            bubbles: true,<br>            composed: true<br>        }))<br>    }<br>}</pre><p>XML:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;LightningComponentBundle xmlns=&quot;http://soap.sforce.com/2006/04/metadata&quot;&gt;<br>    &lt;apiVersion&gt;66.0&lt;/apiVersion&gt;<br>    &lt;isExposed&gt;true&lt;/isExposed&gt;<br>    &lt;targets&gt;<br>        &lt;target&gt;lightning__AgentforceInput&lt;/target&gt;<br>    &lt;/targets&gt;<br>&lt;/LightningComponentBundle&gt;</pre><p><strong>Lightning Type Creation:</strong></p><p>Now that we have created the LWC, we have to associate this LWC with the Apex Custom Nested Wrapper Class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9m9Ng64jMJ-pvVsDOE3LqA.png" /></figure><p>In the previous article we configured the <strong>Renderer</strong> but this time we will configure the <strong>Editor :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*imQ6JBmf7hjBA-_LsUwQDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HCkqm3F5PwE00Q7YnXsHbg.png" /></figure><p>Save it.</p><p>Now the Lightning Type is also ready to be used with the Agent Action.</p><p><strong>Agentforce Agent, Topic &amp; Action Creation:</strong></p><p>I just create a Simple Agentforce Employee Agent with the below config:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5-XE-v4hkLfnAIUR0u91dw.png" /></figure><p>And also a Topic for Case Creation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zw4ojJHu3rwXEczPkpc-fg.png" /></figure><p>Under this Topic, I have configured the Agent Action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aUzSGGL9LZ0dDn4dkpuWLA.png" /></figure><p>And the main thing to notice is that the Input Rendering have been overriden to make use of the above created Lightning Type.</p><p>When you create the Action it will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KLzq_OlVfRk3AtVeCKiWDw.png" /></figure><p>From which I can select the Lightning Type I have created for this Apex Data Type.</p><p>Also, make sure the <strong>Collect data from user</strong> is checked whenever you are making use of Lightning Types.</p><p>That’s it. We have:</p><ul><li>Defined Apex Action supporting Lightning Type</li><li>Defined LWC to be associated with Lightning Type</li><li>Defined the Lightning Type and associated the required Apex Data Type &amp; LWC</li><li>Modified the Agent Action to make use of the created Lightning Type</li></ul><p><strong>VALIDATION &amp; CONCLUSION:</strong></p><p>So now after all the config is done and I ask the Agent to create a case for me, it prompts me with my Custom UI for it.</p><p>As I said it also includes a Submit Button (which is not part of our LWC to conclude that the input have been given &amp; proceed with action execution)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*o8C53GeIO1Q8T-0uCLU-iw.png" /></figure><p>And the action is executed thus creating a case for me:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*4BMSTw36pz6w2ENajK6Mgg.png" /></figure><p>I hope this article comes to use for you in some way or the other. All these configurations are initially confusing but when you understand the crux of working of Lightning Types I have explained in my previous article &amp; give it some time, it just makes sense in your brain.</p><p>Quite interesting if you ask me how Salesforce has implemented it and also have thought about it instead of just relaying on text to give inputs to the Agent. This is also helps you to perform your own logics in terms of validation, data quality instead of just relaying on the Agents to hopefully work right.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c360fa08a96d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Showing Plain Text — Give Agentforce a Custom UI for Agent Responses with Lightning Types]]></title>
            <link>https://medium.com/@hari626007/how-to-use-lightning-types-to-build-custom-ui-for-agent-responses-fa284dca5382?source=rss-79f4c19c681b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa284dca5382</guid>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[salesforce-agentforce]]></category>
            <category><![CDATA[agentforce]]></category>
            <dc:creator><![CDATA[Hari Baskar S]]></dc:creator>
            <pubDate>Wed, 25 Mar 2026 19:16:37 GMT</pubDate>
            <atom:updated>2026-03-29T20:19:08.283Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Agentforce agents can retrieve responses from multiple Agent Actions, but these responses are rendered as plain text by default.</p><p>In many cases, we may want to present these responses using a custom UI. This is where Lightning Types comes into the picture.</p><p>Lightning Types can be used for:</p><ul><li><strong>Displaying</strong> the output of an action in a Custom UI within the Agent Interface</li><li><strong>Get data</strong> from the User for an action in a Custom UI within the Agent Interface</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqQAFyfXg0P84KHZPwY-Nw.png" /></figure><p><strong>UNDERSTANDING THE CRUX OF LIGHTNING TYPES:</strong></p><p>We have to understand some basics of how the Agent unwraps the Invocable Method’s Input &amp; Output Parameters.</p><p>An Invocable Method should:</p><ul><li>Always take a List of Input which can be :<br>- List&lt;Primitive_DataTypes&gt;<br>- List&lt;sObject&gt;<br>- List&lt;CustomWrapper&gt; etc</li><li>Always returns a List of Output which can be :<br>- List&lt;Primitive_DataTypes&gt;<br>- List&lt;sObject&gt;<br>- List&lt;CustomWrapper&gt; etc</li></ul><p>You can get more detailed info <a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm"><strong>here</strong></a></p><p>I.e., it handles data always as a list. And when we associate this Invocable Method with an Agent Action, the Agent always unwrap this List and thus gets the access to the data. So considering this if an Invocable Method is returning :</p><ul><li>List&lt;Primitive_DataType&gt;</li><li>List&lt;sObject&gt;</li><li>List&lt;Simple_CustomWrapper&gt;</li></ul><p>This approach does not work effectively with Lightning Types. If we want to work with Lightning Types then we should always make use of Nested Custom Wrapper Classes. This is because of one important reason which is that we <strong>cannot override the default Lightning Type for primitive data types</strong> like String, Number, Boolean, Data, Date Time etc which you will be able to see when you see the pre-configured Lightning Types in your org via <strong>Setup &gt; Lightning Types </strong>and as the above return types would ultimately return a primitive type, we wont be able to override the Lightning Type configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLYP-d_zbUGFrg5vSih_BQ.png" /><figcaption>All the Lightning Types with Source as Standard cannot be overridden</figcaption></figure><p>Let me show a demo here. This is a Invocable Method which returns a basic List&lt;String&gt;</p><pre>public with sharing class InvalidInvocablemethodOutput {<br>    @InvocableMethod(label = &#39;Get User Email - Invalid&#39; description = &#39;This can be used for getting the Email of an user for a given username&#39;)<br>    public static List&lt;String&gt; getUserEmail(List&lt;String&gt; username) {<br>        List&lt;User&gt; users = [SELECT Id, Email, Username FROM User WHERE Username IN :username];<br>        List&lt;String&gt; userEmails = new List&lt;String&gt;();<br>        for (User user : users) {<br>            userEmails.add(user.Email);<br>        }<br>        return userEmails;<br>    }<br>}</pre><p>And when I try to configure the Agent Action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*re2AjaIftQfJjBTYjDhFrg.png" /></figure><p>And as you can see its lightning__textType which is a Primitive Data Type which cannot be overridden by a Lightning Type.</p><p>And if I make use of a Simple Custom Wrapper class as the output as in the below defintion:</p><pre>public with sharing class InvalidInvocablemethodOutput {<br>    @InvocableMethod(label = &#39;Get User Email - Invalid&#39; description = &#39;This can be used for getting the Email of an user for a given username&#39;)<br>    public static List&lt;EmailDataWrapper&gt; getUserEmail(List&lt;String&gt; username) {<br>        List&lt;User&gt; users = [SELECT Id, Email, Username FROM User WHERE Username IN :username];<br>        List&lt;String&gt; userEmails = new List&lt;String&gt;();<br>        for (User user : users) {<br>            userEmails.add(user.Email);<br>        }<br>        EmailDataWrapper emailDataWrapper = new EmailDataWrapper();<br>        emailDataWrapper.emailData = userEmails;<br>        return new List&lt;EmailDataWrapper&gt;{emailDataWrapper};<br>    }<br><br>    public class EmailDataWrapper {<br>        @InvocableVariable(label = &#39;Emails Data&#39; description = &#39;List of user emails for the given username&#39;) public List&lt;String&gt; emailData;<br>    }<br><br>}</pre><p>Then the output type will be lightning__listType which is again a standard value whose Lightning Type cannot be overridden. This is because how the Agent unwraps the data and it just finds a list of data which is again just primitive with a lightning type defined already.</p><p>Now comes the Nested Custom Wrapper which will work. Below is an example:</p><pre>public with sharing class InvalidInvocablemethodOutput {<br>    @InvocableMethod(label = &#39;Get User Email - Invalid&#39; description = &#39;This can be used for getting the Email of an user for a given username&#39;)<br>    public static List&lt;OuterWrapper&gt; getUserEmail(List&lt;String&gt; username) {<br>        List&lt;User&gt; users = [SELECT Id, Email, Username FROM User WHERE Username IN :username];<br>        List&lt;String&gt; userEmails = new List&lt;String&gt;();<br>        for (User user : users) {<br>            userEmails.add(user.Email);<br>        }<br>        EmailDataWrapper emailDataWrapper = new EmailDataWrapper();<br>        emailDataWrapper.emailData = userEmails;<br>        OuterWrapper outerWrapper = new OuterWrapper();<br>        outerWrapper.emailDataWrapper = emailDataWrapper;<br>        return new List&lt;OuterWrapper&gt;{outerWrapper};<br>    }<br><br>    public class OuterWrapper {<br>        @InvocableVariable(label = &#39;Email Data&#39; description = &#39;Email Data for the requested Username&#39;)<br>        public EmailDataWrapper emailDataWrapper;<br>    }<br><br>    public class EmailDataWrapper {<br>        @InvocableVariable(label = &#39;Emails Data&#39; description = &#39;List of user emails for the given username&#39;) public List&lt;String&gt; emailData;<br>    }<br><br>}</pre><p>And now if Itry to create a Agent Action for the above Invocable Method, then this will be the output type:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_XL2_9ZqMek8702l11esyw.png" /></figure><p>This output type is a Custom Data Type which can be now overridden by a a Custom Lightning Type.</p><p>The same applies to Lightning Types to gather input. It should also be a Nested Custom Wrapper class.</p><p><strong>SUMMARY:</strong></p><ul><li>Any Agent Actions defined via Invocable Methods either for gather data or display data must make use of a <strong>Nested Custom Wrapper</strong> <strong>Class </strong>which will be a Custom Data Type which can be overridden by a Lighting Type.</li><li>Standard Lightning Types cannot be overridden</li></ul><p><strong>STEPS FOR USING LIGHTNING TYPES:</strong></p><ul><li>Define an Agent Action with a Nest Custom Wrapper for Input/Output based on need.</li><li>Define a LWC which will handle the data from the agent</li><li>Customise the Custom Wrapper Type in Lightning Type settings</li><li>Configure the Agent Action with the above Invocable Method.</li><li>Override the default Output Rendering for your Wrapper with your above created Lightning Type</li></ul><p><strong>USING LIGHTNING TYPES TO DISPLAY DATA FROM AGENT ACTION:</strong></p><p>First we have to define an Agent Action and for me am taking a simple action which will give me a User’s email for a given Username. The class definition is as below:</p><pre>public with sharing class GetUserEmailInvocableAction {<br>    @InvocableMethod(label = &#39;Get User email&#39; description = &#39;This can be used to get email of the user for a given username&#39;)<br>    public static List&lt;OutputWrapper&gt; getUserEmail(List&lt;String&gt; username) {<br>        List&lt;User&gt; users = [SELECT Id, Email, Username FROM User WHERE Username IN :username];<br>        Map&lt;String, String&gt; userToEmailMap = new Map&lt;String, String&gt;();<br>        for (User user : users) {<br>            userToEmailMap.put(user.Username, user.Email);<br>        }<br>        EmailDataWrapper emailDataWrapper = new EmailDataWrapper();<br>        emailDataWrapper.emailData = userToEmailMap;<br>        <br>        OutputWrapper outputWrapper = new OutputWrapper();<br>        outputWrapper.emailDataWrapper = emailDataWrapper;<br>        <br>        return new List&lt;OutputWrapper&gt;{outputWrapper};<br>    }<br>    <br>    public class OutputWrapper {<br>        @InvocableVariable(label = &#39;Email Data&#39; description = &#39;Email Data for the requested Username&#39;)<br>        public EmailDataWrapper emailDataWrapper;<br>    }<br>    <br>    public class EmailDataWrapper {<br>        public Map&lt;String, String&gt; emailData;<br>    }<br>}</pre><p>And as we discussed we can see the output is a List&lt;Nested_Custom_Wrapper&gt; which can be overridden.</p><p>Second we have to create a LWC which will have :</p><ul><li>Private data member to hold the data from agent</li><li><strong>@api</strong> annotated getter &amp; setter named <strong>value</strong></li><li>XML configuration to include a target <strong>lightning__AgentforceOutput</strong></li></ul><p>The value property acts as the entry point through which the Agent injects data into the component. The structure of this data matches the Apex wrapper defined in the Invocable Method.</p><p>Below is a sample LWC:</p><p>JS:</p><pre>import { LightningElement, api } from &#39;lwc&#39;;<br><br>export default class DisplayEmail extends LightningElement {<br>    _userEmail = [];<br><br>    @api<br>    get value() {<br>        return this._userEmail;<br>    }<br>    set value(data) {<br>        for (let [key, value] of Object.entries(data.emailData)) {<br>            let userData = {};<br>            userData[&#39;username&#39;] = key;<br>            userData[&#39;email&#39;] = value;<br>            this._userEmail.push(userData);<br>        }<br>    }<br><br>}</pre><p>HTML:</p><pre>&lt;template&gt;<br>    &lt;div class=&quot;slds-box slds-theme_default&quot;&gt;<br>        &lt;h3 class=&quot;slds-text-heading_medium&quot;&gt;Custom Email Display Component:&lt;/h3&gt;<br>        &lt;template for:item=&quot;user&quot; for:each={_userEmail}&gt;<br>            &lt;div key={user.username}&gt;<br>                Email of {user.username} is {user.email}<br>            &lt;/div&gt;<br>        &lt;/template&gt;<br>    &lt;/div&gt;<br>&lt;/template&gt;</pre><p>XML:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;LightningComponentBundle xmlns=&quot;http://soap.sforce.com/2006/04/metadata&quot;&gt;<br>    &lt;apiVersion&gt;66.0&lt;/apiVersion&gt;<br>    &lt;isExposed&gt;true&lt;/isExposed&gt;<br>    &lt;targets&gt;<br>        &lt;target&gt;lightning__AgentforceOutput&lt;/target&gt;<br>    &lt;/targets&gt;<br>&lt;/LightningComponentBundle&gt;</pre><p>So the flow would be</p><ul><li>Agent gets the response from the action</li><li>Response will be set into the private data member via a public setter</li><li>Data is now rendered based on need.</li></ul><p>Now the LWC (UI via which we are displaying the data is ready) and now we will configure the Lightning Type:</p><ul><li>Setup &gt; Lightning Types &gt; New Lightning Types</li><li>Give it a Label &amp; Description</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8P6hGIJ9uC7FzMXrMw2idA.png" /></figure><ul><li>Click on Next and choose the type as <strong>Apex </strong>and choose the necessary output type to overridde.</li></ul><p>Now there will be a lot of values and one small trick I would suggest is configure the Agent Action before hand so you will know what will be the exact value and for me I can see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tb0qkKSfQBrb7tBwuMXrBQ.png" /></figure><p>And now I can search for it in the Lightning Types and create it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pHMJGvw0E22DJJwwXG9TZg.png" /></figure><p>So till now we have given :</p><ul><li>Custom Output Type</li><li>LWC to display</li><li>Lightning Type for the Custom Output Type</li></ul><p>Now we will link the LWC for this Custom Output Type in the Lightning Type as:</p><ul><li>Your Custom Lightning Type &gt; UI Configuration</li><li>As we are going to display data, go to Render &gt; Change <strong>Renderer Override</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AUZ9DxNo2cBl5KTnKwx7hA.png" /></figure><ul><li>Now choose the LWC to be used:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kb0I1cqqCVe0_fuJRRes2g.png" /></figure><ul><li>Now it will be configured as:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZGY7MnC3x8A4lmSXIL-zlQ.png" /></figure><ul><li>Save it. (Save button on top)</li></ul><p>Now to the last setup to make use of the Lightning Type to display data:</p><ul><li>Create an Agent Action by:<br>Type: Apex<br>Category: Inocable Method</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wn_LDHqb1vIeyGupN2a3sA.png" /></figure><ul><li>Configure the rest of the action and for configuring the Lightning Type make sure to:<br>- Check “Show in Conversation” (very important)<br>- Choose the Custom Lightning Type</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rsPKx3hKB7dExfZX62vetA.png" /></figure><p>Thats it.</p><p>TESTING IT OUT:</p><p>I just refreshed the agent chat interface and prompted it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*Wj_9kok2syehc8y1qtZ9Dw.png" /></figure><p>And you can see that the agent got the data but is also displaying using our custom LWC.</p><p><strong>CONCLUSION:</strong></p><p>This article has already gone longer than I expect because of which I am cutting it short and covering how we can make use of Lightning Types to get data from the User via the Agent in another article.</p><p>But in this arcticle we have gotten the crux of how Lightnign Types works and what is needs for configuring it for it to be used for displaying data in the Agent Interface.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa284dca5382" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Hidden Serialization Trap in Salesforce Async Apex]]></title>
            <link>https://medium.com/@hari626007/the-hidden-serialization-trap-in-salesforce-async-apex-69e4ffd7a5c3?source=rss-79f4c19c681b------2</link>
            <guid isPermaLink="false">https://medium.com/p/69e4ffd7a5c3</guid>
            <category><![CDATA[async-apex]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[salesforce-asynchronous]]></category>
            <dc:creator><![CDATA[Hari Baskar S]]></dc:creator>
            <pubDate>Tue, 17 Mar 2026 03:59:01 GMT</pubDate>
            <atom:updated>2026-03-17T03:59:01.976Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*urE-BMijsok0iZwDWzUTYg.png" /></figure><p>Have you ever faced a scenario where you have your Scheduled Job running but then its not running exactly as hoped mainly when you make use of a Constructor to populate some data ?</p><p>Let me give you an example job:</p><pre>public with sharing class SampleSerialisationScheduled  implements Schedulable{<br>    public List&lt;Case&gt; cases = new List&lt;Case&gt;();<br>    <br>    public SampleSerialisationScheduled(){<br>        cases = [SELECT Id, Subject, Description FROM Case WHERE Owner.Username = &#39;MY_USER_NAME&#39;];<br>    }<br>    <br>    public void execute(SchedulableContext sc){<br>        System.debug(&#39;Size of Case: &#39;+ cases.size());<br>    }<br>}</pre><p>Seems simple right?</p><ul><li>You Schedule the Job</li><li>It calls the Constructor on every Job Instance</li><li>Gets the Data and prints me the size of it</li></ul><p>But in the above three steps, <strong>“It calls the Constructor on every Job Instance” </strong>differ from what actually happens.</p><p>Whenever we Scheduled the job using <strong>System.schedule(‘Job Name’, CRON_EXPRESSION, new ClassName()) ,</strong></p><ul><li>Salesforce Initialise a instance of the Scheduled Class</li><li>Executes the Constructor defined in the Class</li><li>Now after the object is defined based on the constructor, its <strong>Serialised </strong>and stored in Salesforce. i.e., <strong>all the instance variables are persisted</strong> across jobs.</li><li>Whenever the Scheduled Job needs to be executed, its De-Serialised and only the <strong>.execute() </strong>method is executed.</li></ul><p>Meaning the Constructor wont be called again and again on every execution because of which if there is any data needs to be initiated in the Constructor on every run, it wont be initiated on every run.</p><p>It will be same data which was initiated when the Job was initially scheduled i.e., in my above example the query would have not been run after its first time during my scheduling and would now contain <strong>stale data</strong>.</p><p><strong>A SMALL DEMO FOR THE ABOVE CLASS:</strong></p><p>I have scheduled the Job for every 3 minutes to run and during scheduling, I had 26 Cases satisfying the query and later I created one more case. But on every job instance, we will be seeing 26 only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXNjU35xbu7PPryISSJvQg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DGpJ3RuRAEKnnZmNXYLBtg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WP5FehGIxu6WMYkHW79oDA.png" /></figure><p>And so on i.e., for every job it will be 26 and will never be 27.</p><p>But now lets say I execute the job directly from the Anonymous Window like this:</p><pre>SampleSerialisationScheduled sc = new SampleSerialisationScheduled();<br>sc.execute(null);</pre><p>Now a new instance of the Job will be created which will call the Constructor which will have the updated instance variables and then the execute() method will be executed.</p><p>So whats the fix you may ask,</p><p>Just move the query into the execute method and new data will be fetched everytime.</p><p>This would be an issue only when the Constructor initialises data which may mutate as in case of Query Result, Date, DateTime etc. But if your constructor just initialises static data then there wont be any issue.</p><p><strong>DOES THIS OCCUR FOR OTHER ASYNC APEX JOBS ?</strong></p><p>Yep, Serialisation for other Async Apex like Batch &amp; Queueable but in case of them, we will be executing it as:</p><pre>Database.executeBatch(new MyBatchApexClass(),200)<br>System.enqueueJob(new MyQueueableClass());</pre><p>So on every execution, a new instance of it will be created meaning the Constructor will be ran again and again and you will having your updated data. But in case of Scheduled Job, the same instance is used across multiple jobs overtime because of which the data becomes stale.</p><p>And in case of Batch Jobs this is easily seen when the serialised output of the constructor (instance variables) is what will be loaded for every execute transaction because of which value set by the Constructor is visible to you but not the value set by any other start or execute or finish method. This is why we make use of Database.Stateful which will be updating the serialised object back to give the updated value of those instance variables to other transactions.</p><p>Below is a sample Batch class to validate the same:</p><pre>public with sharing class SampleBatch implements Database.Batchable&lt;sObject&gt;{<br>    <br>    public String trackerString;<br>    <br>    public SampleBatch(){<br>        trackerString = &#39;Value set by Constructor&#39;;<br>    }<br>    <br>    public Database.QueryLocator start(Database.BatchableContext bc){<br>        System.debug(&#39;Before Change in start: &#39;+trackerString);<br>        trackerString = &#39;Value set by start()&#39;;<br>        String userName = &#39;USER_NAME&#39;;<br>        return Database.getQueryLocator(&#39;SELECT Id, Subject, Description FROM Case WHERE Owner.Username = :userName&#39;);<br>    }<br>    <br>    public void execute(Database.BatchableContext bc, List&lt;Case&gt; scope){<br>        System.debug(&#39;Value in execute(): &#39;+trackerString);<br>        trackerString = &#39;Value set by execute()&#39;;<br>        System.debug(&#39;Scope Size: &#39;+scope.size());<br>    }<br>    <br>    public void finish(Database.BatchableContext bc){<br>        System.debug(&#39;Value in finish(): &#39;+trackerString);<br>        System.debug(&#39;Batch Ran!!&#39;);<br>    }<br>}</pre><p>And below is the log for each transaction:</p><p>start():</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99jvgtisn9HJMjZdj8Y8og.png" /></figure><p>execute():</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zkAp0xKxVTj7IdBsKdEKPQ.png" /></figure><p>finish():</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1gTaqt2_QVRM0rjXZswF8g.png" /></figure><p>So the values of the instance variables defined by the Constructor which gets serialised is what loaded again and again for every single transaction. Unless we make of <strong>Database.Stateful</strong> because of which the changes are written back to the instance variables and serialised back for the next transaction.</p><p>Hopefully this clarifies a lot of doubts on the scope of Serialisation in Async Apex and how they will impact your variables.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69e4ffd7a5c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Salesforce Agentforce: Improving the Multimodal Capability of Agent to understand Excel & Word]]></title>
            <link>https://medium.com/@hari626007/expanding-the-multi-modal-capability-of-agent-to-understand-excel-word-files-in-salesforce-d488601b94dd?source=rss-79f4c19c681b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d488601b94dd</guid>
            <category><![CDATA[retrieval-augmented-gen]]></category>
            <category><![CDATA[agentforce]]></category>
            <category><![CDATA[multimodal-ai]]></category>
            <category><![CDATA[microsoft-office]]></category>
            <category><![CDATA[salesforce]]></category>
            <dc:creator><![CDATA[Hari Baskar S]]></dc:creator>
            <pubDate>Mon, 12 Jan 2026 19:35:17 GMT</pubDate>
            <atom:updated>2026-01-13T12:52:18.978Z</atom:updated>
            <content:encoded><![CDATA[<p>Agentforce provides us method to get answer based on Notes &amp; Attachment for a record but these attachments are limited to PDF &amp; Text files. This ignores major file format like Excel or Word which is how most of the companies have their unstructured data.</p><p>So as always as Salesforce Developer, we have to build custom solutions for the same and below is mine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwQ4Y2WKpbpAGl11vGYawg.png" /></figure><p>ARCHITECTURE:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B3PqE4t7a6yQjmRElYU0Wg.png" /></figure><p>We are aware that Agentforce supports PDF files, but not Excel or Word files. Therefore, we convert Excel and Word files when they are uploaded into Salesforce, and then use the converted PDFs as data that the agent can use to answer user questions. This is done using the flow below:</p><ul><li>The user uploads an attachment (e.g., PDF, Excel, or Word) to a record. We filter for the Excel &amp; Word files, extract the content and store the content from those Files into PDF using Apex.</li><li>But then now we have to link the converted file to some record. We could link it to the original record to which the Excel or Word file was attached, but this might overwhelm users who view it.</li><li>So here we are going to make use of a Custom Object called <strong>SObject Attachment </strong>which will be present for each and every record and will contain the converted attachments.</li><li>SObject Attachment will act the Parent in the Lookup that it will have from the normal record because we will be making use of the Prompt Template to get the Files to be sent to the LLM and its easy it get it via Related Lists for a given record. So we can traverse from the Main Record &gt; Parent Record &gt; Related List of Parent Record in the prompt template.</li><li>So now in the Prompt Template we will have two related list:<br>- Files Related list of Record.<br>- Files Related list of Record.SObject_Attachment__c</li><li>Now that the prompt template contains both normal files and converted files, the multimodal agent can use all the PDFs to answer any user question.</li></ul><p>The entire flow can simplified as below:</p><pre>User Uploads File (Excel/Word)<br>         ↓<br>ContentDocumentLink Trigger (After Insert/Update)<br>         ↓<br>Filter &amp; Validate (File type, Object type, Size)<br>         ↓<br>Enqueue Conversion Job (Future - Async)<br>         ↓<br>Extract Text Content (XLSX Util / Word Parser)<br>         ↓<br>Create SObject_Attachment__c Record <br>         ↓<br>Generate PDF from Text (Blob)<br>         ↓<br>Link PDF to SObject_Attachment__c<br>         ↓<br>AI Prompt Retrieves: Original PDFs + Converted PDFs<br>         ↓<br>Filter out Original Excel/Word files<br>         ↓<br>AI Agent Processes All PDF Content</pre><p><strong>USE CASE CONSIDERATION:</strong></p><p>I have a considered a use case where my main object is Account and it will contain all the attachments uplaoded by the user.</p><p>The users will now ask questions based on the attachments present in the account.</p><p><strong>IMPLEMENTATION:</strong></p><p>Before we proceed we need to perform the below two tasks:</p><ul><li>Install <a href="https://developer.salesforce.com/blogs/2025/02/reading-excel-files-using-the-apex-zip-functionality">Excel Util package</a> (Scorll down for package links)</li><li>Create Object relationship.</li></ul><p>Data Modelling:</p><ul><li>Setup &gt; Object Manager &gt; New Custom Object &gt; Name it <strong>SObject Attachment</strong> &gt; Config the rest of the settings however you want (it doesnt matter)</li><li>For the sake of this example, am taking account. So go to Setup &gt; Object Manager &gt; Account &gt; Fields &amp; Relationship &gt; New Field &gt; Choose the type as Lookup &gt; Create a lookup to the SObject Attachment object.</li></ul><p>After the setup it should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aOi12httGkshzXsmMi-xqw.png" /><figcaption>Data Model for Attachments</figcaption></figure><p>First we will need to create a <strong>Trigger on ContentDocumentLink &amp; associated Trigger Helper Class </strong>which will check the file type and determine if the given file needs to be converted into PDF or not.</p><pre>trigger ContentDocumentLinkTrigger on ContentDocumentLink (after insert) {<br>    ContentDocumentLinkTriggerHelper.generatePDFForExcelAndWord(Trigger.new);<br>}</pre><pre>public with sharing class ContentDocumentLinkTriggerHelper {<br>    public static void generatePDFForExcelAndWord(List&lt;ContentDocumentLink&gt; contentDocumentLinks){<br>        Set&lt;Id&gt; cdIds = new Set&lt;Id&gt;();<br>        Map&lt;Id, Id&gt; cdToCdlLinkedEntityId = new Map&lt;Id, Id&gt;();<br>        <br>        for (ContentDocumentLink cdl : contentDocumentLinks){<br>            cdIds.add(cdl.ContentDocumentId);<br>            cdToCdlLinkedEntityId.put(cdl.ContentDocumentId, cdl.LinkedEntityId);<br>        }<br>        <br>        List&lt;ContentVersion&gt; contentVersions = [SELECT Id, ContentDocumentId FROM ContentVersion WHERE ContentDocumentId IN :cdIds AND FileExtension IN (&#39;xlsx&#39;,&#39;docx&#39;) ];<br>        for (ContentVersion cv : contentVersions) {<br>            Id recordId = (Id) cdToCdlLinkedEntityId.get(cv.ContentDocumentId);<br>            String objectAPIName = recordId.getSobjectType().getDescribe().getName();<br>            if (ConstantHelper.trackedObjects.contains(objectAPIName)){<br>                GeneratePDF.generateAndLinkPDF(cv.Id, cdToCdlLinkedEntityId.get(cv.ContentDocumentId), objectAPIName);<br>            }<br>        }<br>    }<br>}</pre><p>If the Trigger determines that it needs to be converted, then it will call a future method in the <strong>GeneratePDF </strong>Class which will perform the conversion.</p><p>Here we are making use of a <strong>Future Method</strong> because:</p><ul><li>Higher Heap Size &amp; CPU Time Limit =&gt; Thus aiding in converting larger files</li><li>Async Processing =&gt; User doesnt have to wait when the upload a file as conversion will happen in the background.</li></ul><p>Conversion of the files is done with the help of below:</p><ul><li><strong>Excel</strong> =&gt; Using the <strong>XLSX Parse Util</strong> which is present as both Managed &amp; Unmanaged package. This needs to be installed in the org.</li></ul><ul><li><a href="https://omkardeokar95.medium.com/read-excel-data-from-and-to-apex-using-lwc-1884ee7da084">Read Excel data from and to Apex using LWC</a></li><li><a href="https://developer.salesforce.com/blogs/2025/02/reading-excel-files-using-the-apex-zip-functionality">Reading Excel Files Using the Apex Zip Functionality</a></li></ul><ul><li><strong>Word</strong> =&gt; Using DOM Class in Apex which just extracts the content of the word document.</li></ul><p>Both together is consolidated into the below class:</p><pre>public with sharing class GeneratePDF {<br>    @future<br>    public static void generateAndLinkPDF(String contentVersionId, String recordId, String objectAPIName){<br>        String sobjectAttachmentQuery = &#39;SELECT Id, SObject_Attachment__c FROM &#39; + objectAPIName + &#39; WHERE Id = :recordId LIMIT 1&#39;;<br>        List&lt;SObject&gt; soa = Database.queryWithBinds(sobjectAttachmentQuery, new Map&lt;String,Object&gt;{&#39;recordId&#39; =&gt; recordId}, AccessLevel.SYSTEM_MODE);<br>        String linkedEntityId = &#39;&#39;;<br>        String possibleSOAId = (String) soa[0].get(&#39;SObject_Attachment__c&#39;);<br>        if (String.isBlank(possibleSOAId)){<br>            SObject_Attachment__c newSoa = new SObject_Attachment__c(Name = objectAPIName+&#39;_&#39;+recordId);<br>            insert as system newSoa;<br>            SObject genericObject = ((Id) recordId).getSobjectType().newSObject(recordId);<br>            genericObject.put(&#39;SObject_Attachment__c&#39;, newSoa.Id);<br>            update as system genericObject;<br>            linkedEntityId = newSoa.Id;<br>        }else {<br>            linkedEntityId = possibleSOAId;<br>        }<br>        ContentVersion orgFile = [SELECT Id, VersionData, Title, FileExtension FROM ContentVersion WHERE Id = :contentVersionId];<br>        ContentVersion cv =  new ContentVersion();<br>        String fileName = orgFile.Title + &#39;_converted_aiRAG&#39;;<br>        cv.Title =  fileName;<br>        cv.PathOnClient = fileName + &#39;.pdf&#39;;<br>        String content = generateContentFromExcelOrWord(orgFile.VersionData, orgFile.FileExtension);<br>        cv.VersionData = Blob.toPdf(content);<br>        insert as system cv;<br>        <br>        ContentDocumentLink cdl = new ContentDocumentLink();<br>        cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :cv.Id].ContentDocumentId;<br>        cdl.LinkedEntityId = linkedEntityId;<br>        cdl.ShareType = &#39;V&#39;;<br>        cdl.Visibility = &#39;AllUsers&#39;;<br>        insert cdl;<br>    }<br>    <br>    public static String generateContentFromExcelOrWord(Blob versionData, String type){<br>        String content = null;<br>        switch on type {<br>            when &#39;xlsx&#39; {<br>                content = generateContentFromExcel(versionData);<br>            }<br>            when &#39;docx&#39; {<br>                content = generateContentFromWord(versionData);<br>            }<br>        }<br>        return content;<br>    }<br>    <br>    public static String generateContentFromExcel(Blob versionData){<br>        Compression.ZipReader reader = new Compression.ZipReader(versionData);<br>        Map&lt;String,Compression.ZipEntry&gt; entries = reader.getEntriesMap();<br>        Object[][][] xlsxDataAsArray = xlsx.Parse.toArrayInverted(entries);<br>        return JSON.serialize(xlsxDataAsArray);<br>    }<br>    <br>    public static String generateContentFromWord(Blob versionData){<br>        Compression.ZipReader reader = new Compression.ZipReader(versionData);<br>        Compression.ZipEntry documentEntry = reader.getEntry(&#39;word/document.xml&#39;);<br>        Blob documentXml = reader.extract(documentEntry);<br>        String xmlContent = documentXml.toString();<br>        String textContent = extractTextFromDocumentXml(xmlContent);<br>        return textContent;<br>    }<br>    public static String extractTextFromDocumentXml(String xmlContent) {<br>        String textContent = &#39;&#39;;<br>        Dom.Document doc = new Dom.Document();<br>        doc.load(xmlContent);<br>        Dom.XmlNode root = doc.getRootElement();<br>        textContent = extractTextNodes(root);<br>        return textContent.trim();<br>    }<br>    <br>    // Recursive method to find all text nodes<br>    public static String extractTextNodes(Dom.XmlNode node) {<br>        String text = &#39;&#39;;<br>        if (node.getName() == &#39;t&#39; &amp;&amp; node.getNamespace() == &#39;http://schemas.openxmlformats.org/wordprocessingml/2006/main&#39;) {<br>            text += node.getText();<br>        }<br>        for (Dom.XmlNode child : node.getChildElements()) {<br>            text += extractTextNodes(child);<br>        }<br>        return text;<br>    }<br>}</pre><p>What we have accomplished till now?</p><ul><li>When user upload a file based on the file Excel &amp; Word file will be converted.</li><li>Converted Files will be stored in a separate object.</li></ul><p>Now, we have to make use of the created documents in a Prompt Template along with a Multimodal LLM like <strong>Google Gemini 2.5 Pro </strong>as below:</p><ul><li>Setup &gt; Prompt Builder &gt; New Prompt Template &gt; Type as Flex</li><li>Give it a Name &amp; click on Next</li><li>Add two Inputs:<br>- Name: <strong>Account</strong>, Source Type: SObject, Object: Account<br>- Name: <strong>Question</strong>, Source Type: Free Text</li><li>Paste the below content:</li></ul><pre>{!$RelatedList:Account.CombinedAttachments.Records}<br>{!$RelatedList:Account.SObject_Attachment__r.CombinedAttachments.Records}<br>The above is the list of all the attachments that are attached to the below record<br>{!$RecordSnapshot:Account.Snapshot}<br><br>Only based on the information given above, try to answer questions. <br>Rules to Follow:<br>1. Answer should be based on the data given above. No other sources. <br>2. The attachment also contains some excel file which is converted into PDF document for your understanding. So you can ignore the excel file and focus on the converted files. All the converted files will have the suffix &quot;_converted_aiRAG&quot;<br>4. If the answer is from an attachment, then give the source as the original file from which the _converted_aiRAG file have been generated. For example if you find the answer in the file &quot;AI_Input_converted_aiRAG.pdf&quot;, then there should be &quot;AI_Input.xlsx&quot; or &quot;AI_Input.docx&quot; Mention that as the source only. Not the _converted_aiRAG source. You can mention the _converted_aiRAG file only when the original source is not there in the attachment related list. <br>5. In case you got the answer from the record information, say &quot;From Record&quot;<br>6. If you are not able to find an answer, its okay to say that you dont know the answer.<br><br>Format of the Response:<br>Your response for the question<br>Source: Source from where you got the response. <br><br>The above format must be followed for each &amp; every questions asked.<br><br>Question: <br>{!$Input:Question}</pre><ul><li>Make sure to choose the model as <strong>Google Gemini 2.5 Pro. </strong>(You can choose any other LLM Model supporting Multimodality but I found this one works well for me)</li><li>Save &amp; Activate the Prompt Template. Also you can Debug by previewing it.</li></ul><p>Now our prompt template is ready and needs to be just used by an Agent. But instead of allowing the agent to directly invoke the Prompt Template, we will make the agent to invoke a Flow which in turn invokes the Prompt Template which gives us the response.</p><p>The above is done because:</p><ul><li>When we invoke the Prompt Template directly from the Agent, the Prompt Template expects an Instace of a Record from the Agent.</li><li>The Agent can make use of General CRM to query the record and pass the instance but I have observed that most of the time it passes the record Id only.</li><li>So we allow the Agent to pass the Record ID with the Question to the Flow which will make use of the Get Record Element to get a record instance which can be passed to the prompt template to get the response and the flows sends back the response to the agent.</li></ul><p>The above described flow is created as:</p><ul><li>Setup &gt; Flows &gt; New Flow &gt; Autolaunched (Not Trigger) Flow</li><li>Create three resources:</li></ul><pre>Resource Type: Text<br>API Name: recordId<br>Description: This is the Record Id of the account for which the question have been asked.<br>Available for Input: True<br><br>Resource Type: Text<br>API Name: question<br>Description: This is the question asked by the User.<br>Available for Input: True<br><br>Resource Type: Text<br>API Name: promptResponse<br>Description: This is answer for the question asked by the user.<br>Available for Output: True</pre><ul><li>Add a Get Element after the Start with the below config:</li></ul><pre>Type: Get Element<br>Name: Get Account<br>Get Records of This Object: Salesforce Object<br>Object: Account<br>Filter Condition: Account Id equals recordId<br>How to Store Record Data: Choose fields and let Salesforce do the rest. <br>Select Account Fields to Store in Variable: Id</pre><ul><li>Now add the above created Prompt Template as a Action to the flow:</li></ul><pre>Type: Action<br>Label: Get Response for User Question<br>Account: {!Get_Account}<br>Question: {!question}<br>View Output Resources: Manually assign variables (advanced)<br>Map Prompt Response promptResponse Variable: {!promptResponse}</pre><ul><li>Save &amp; Activate the Flow.</li></ul><p>Now we will create an Agent which will make use of the above created Flow as a Agent Action to get the required response:</p><ul><li>Setup &gt; Agentforce Agents &gt; New Agent &gt; Agentforce Employee Agent</li><li>Give it a Name, Description, Role &amp; Company.</li><li>Topics &gt; New Topic with the below config:</li></ul><pre>Name: Object Specific Question Response<br>Classification Description: This can be used to used answer any question that the user for a particular object. It answer by getting the response from the Object, Related Records of the Object, Attachments related to the Object.<br>Scope: Limited to answering question for a record.<br>Instructions:<br>  1. The record must be passed to the prompt not only the record Id.<br>  2. This is the only topic that must be used to answer any question that the user may have.<br>  3. No generic response or response from other source are allowed.</pre><ul><li>Now go to the created Topic and create a new action with the below config:</li></ul><pre>Reference Action Type: Flow<br>Reference Action: Above_Created_Flow<br>Make sure to select the below as Require Input:<br>  1. Question<br>  2. Record Id</pre><ul><li>Finish it and now the action becomes a part of the topic.</li></ul><p>So now with this we are done with the setup. Summarising what we have done:</p><ul><li>Created the SObject Attachment Object &amp; a lookup from Account to SObject Attachment.</li><li>Created a ContentDocumentLink Trigger &amp; Trigger Helper Class</li><li>Created a GeneratePDF Class for converting Excel &amp; Word to PDF. (Note: Please install the XLSX Parser Package before hand)</li><li>Created a Prompt Template to include the attachments</li><li>Invoke the Prompt Template from Flow</li><li>Create an Agent with the Flow as an Agent Action</li></ul><p><strong>TESTING:</strong></p><ul><li>For the purpose of testing I have some excel file which I have uploaded to the account record &amp; I can see the converted PDF files for the same.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bRJJVvxJ-xTjLxC6w4XMrA.png" /><figcaption>Attachment in Account Object</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jsTk3gUP_B7Z2FKiE5-hqw.png" /><figcaption>Attachment in SObject Attachment Object for the above Account Record</figcaption></figure><ul><li>Below is the content of the file:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISHMuq77KbyBOhb8Njfmaw.png" /></figure><ul><li>Setting up the Conversation preview with the Object API Name &amp; Record Id</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*AWxfrYYPoNPBlI6Kur3LAw.png" /></figure><ul><li>Now on asking the agent a question based on the excel file:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*RuIDx-VVfJyhGqmwP7FKKQ.png" /></figure><p>So we can see that the agent was able to parse the PDF from the converted Excel and use it to reason for a question asked to it.</p><p><strong>CONCLUSION:</strong></p><p>Hope you are happy with the results because I am very much happy about it. Its very interesting to think how the data have flown from multiple places to give us this response.</p><p>Its all possible because of the way how the tools in Salesforce interact with each other to create something very new out of it. It just fascinates me.</p><p>Thank you for reading my rant. See you in my next article. Till then</p><p>✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d488601b94dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Access Provisioning for Flow in Winter ‘25]]></title>
            <link>https://medium.com/@hari626007/access-provisioning-for-flow-in-winter-25-3dfdd5100824?source=rss-79f4c19c681b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dfdd5100824</guid>
            <category><![CDATA[salesforce-flow]]></category>
            <category><![CDATA[salesforce-access-control]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[access-management]]></category>
            <category><![CDATA[salesforce]]></category>
            <dc:creator><![CDATA[Hari Baskar S]]></dc:creator>
            <pubDate>Mon, 12 Jan 2026 18:27:16 GMT</pubDate>
            <atom:updated>2026-01-12T18:27:16.365Z</atom:updated>
            <content:encoded><![CDATA[<p>In Salesforce, Flow can be executed by users who have access to.</p><p>Lets consider a newly created User. By default they wont have the access to run any flow. The access to Flow can be restricted via:</p><ul><li>User Level <strong>Flow User </strong>Access</li><li>Profile or PS Level <strong>Run Flow</strong> Access</li><li>Flow Level Access based on <strong>Override</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4pDksY8h1UlNMqMfko8QTQ.png" /></figure><p><strong>Provide Access via Flow User — User Level:</strong></p><p>For the given below user, the Flow User is Unchecked and there are no Flow access given in either Profile or PS level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YrWVi5i5QrdJeCAZ0K5wHQ.png" /></figure><p>Because of which when I execute a Flow as the above user, am thrown this error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MK29-Zi9PABlWI47e163aA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IkqtGAS1UaZ-gH8yXYDQCQ.png" /></figure><p>So I can resolve this by checking the <strong>Flow User as TRUE:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2u5OSVMIIotKs4-lkav0oQ.png" /></figure><p>And now if I try to run the flow, it runs successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ieWE_RPxYuM53ZL0jEhAKQ.png" /></figure><p><strong>Provide Access via Flow User — Profile or PS Level:</strong></p><p>For the above User, I reset the access by making the Flow User as False and now they cant run the flow.</p><p>The above <strong>Flow User Check </strong>gives the User to run any kind of Active Flow (There is one exception, will explain soon) but this needs to be given on an Individual User level to give them that access. What if we want to do for many people and manage it easily too?</p><p>The scaled up method would by providing it via Profile or Permission Set using the <strong>Run Flow </strong>Permission. This can be done as:</p><ul><li>Profile or Permission Set &gt; App Permissions &gt; Flow and Flow Orchestrations</li><li>Check <strong>Run Flows </strong>as True</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wfa8ORj52TlAntfjyD_zGg.png" /></figure><p>And before assigning the PS and with Flow User as False:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nthUnH43DOcB3XL-4pGgGw.png" /></figure><p>After assigning the PS with Run Flow as True but still with Flow User as False:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*scLYzMtxvSG7NNA04if8Bg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhV4Ittp5kzxe93jmrRCGA.png" /></figure><p>This gives access to run flows exactly as how the Flow User on User object does i.e., gives access to run all the flows in the org with one exception similar to the Flow User (again will be explained below)</p><p><strong>Flow Level Access based on Override:</strong></p><p>This is the <strong>exception</strong> that I have been telling you about which when enabled doest respect the access given by the Flow User in User Level or Run Flow in Profile or PS level.</p><p>Both the <strong>Flow User &amp; Run Flow</strong> gives the User the access to run all the flows in the org. But in case we want to restrict users from running a particular flow, we can make use of the <strong>Override Default Behaviour &amp; Restrict Access to Enabled Profiles &amp; PS </strong>which will restrict direct access to the Flow unless provided explicitly via Profile or Permission Set.</p><p>This can be done a individual Flow level as:</p><ul><li>Setup &gt; Flows &gt; Required Flow Drop Down &gt; Edit Access</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*POabwTvXUB021SDpMZWSfw.png" /></figure><ul><li>This will lead to the below screen:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sFi5O-7sqvxrbDDWHjcoYg.png" /></figure><ul><li>Here when we check the checkbox for <strong>Override Default Behaviour &amp; restrict access to enabled Profile &amp; PS</strong>, all the access via the Flow User &amp; Run Flow will be cut.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C89r8UuW_bDAy7atdLYV5Q.png" /></figure><p>And now if try to execute the Flow (With the Run Flow Checked):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EaZTN5Buu75s_9zGy8s3BA.png" /></figure><p>Now we can provision access to the Flow in Profile or PS as:</p><ul><li>Setup &gt; Profile or PS &gt; Flow Access &gt; Add the required Flows.</li><li>Save it</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_XzLZWf3IbnBmkXKUseKUA.png" /></figure><p>And now on executing the same flow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Qkdu4hbAijke5cU_gl1ZA.png" /></figure><p>So we can say that the Flow Level Override takes precedence over the access given by the Flow User or Run Flow access.</p><p><strong>NOTE:</strong></p><ul><li>Also one more interesting thing is this Override can be given to a User without Run Flow or Flow User checked because of which they will be able to execute only this Flow and no other flow in the org.</li></ul><p><strong>CONCLUSION:</strong></p><p>Based on the all the above ways of providing access, the below table must summarise how access is given for users to execute a flow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q6LGCUNP8FE8133OlAfNPQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dfdd5100824" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multi-Agent Orchestration (A2A) in Salesforce Agentforce]]></title>
            <link>https://medium.com/@hari626007/multi-agent-orchestration-a2a-in-salesforce-agentforce-b76234cd0e0e?source=rss-79f4c19c681b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b76234cd0e0e</guid>
            <category><![CDATA[a2a-protocol]]></category>
            <category><![CDATA[salesforce-agentforce]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[agentforce]]></category>
            <dc:creator><![CDATA[Hari Baskar S]]></dc:creator>
            <pubDate>Sun, 11 Jan 2026 07:46:40 GMT</pubDate>
            <atom:updated>2026-01-11T07:46:40.006Z</atom:updated>
            <content:encoded><![CDATA[<p>Multi-Agent Orchestration has two components:</p><ul><li><strong>Helper Agent</strong> =&gt; Can also be called Domain Agents which will take care of all the request related to a particular topic, handles the tasks from the Orchestrator Agent which helps towards the End Goal.</li><li><strong>Orchestrator Agent</strong> =&gt; Breaks down the Complex Request / End Goal into Small Tasks which are then executed by the Helper Agents.</li></ul><p>This involves the Orchestrator Agent interacting with the Helper Agents without any Human Intervention and thus becomes a Agent-to-Agent Interaction i.e., A2A Interaction.</p><p>Native Support for A2A is not present in Agentforce and the below implementation is to overcome the current limitation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iqZjhoaIvhXWbthL5Kdpxw.png" /></figure><p><strong>ARCHITECTURE:</strong></p><p>Below is the Architecture that I used to implement Agent Orchestration in Salesforce:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ztNkTFLlmm-qgf8RURsyKQ.png" /></figure><p><strong>Orchestrator Agent</strong> is the main Agent with which the User will interact. This contains an <strong>Orchestration Topic</strong> which is used to handle the incoming tasks. This topic contains 2 main Apex Defined Actions:</p><ul><li>Prompt Agent Action</li><li>Agent Information Action</li></ul><p><strong>Prompt Agent Action </strong>is a Apex-Define Action which will be used to send a prompt to other agents for which we will make use of <strong>Invoke.Action</strong></p><p><strong>Agent Information Action</strong> is also a Apex-Defined Action which will be used to get all the Actions that can be done by each Agent given to it. This action will be executed once per session to help the orchestrator understand what the agents that are available to it and what they can do. The result of this Action is stored in a Custom Context Variable called <strong>AgentInformation </strong>which can be referred by the Orchestration Agent to plan its set of action.</p><p><strong>Domain Agents </strong>refers to the Helper Agents which can perform their set of tasks and report it back to the Orchestration based on which the Orchestrator will decide what to do next.</p><p>So the Flow will be:</p><ol><li>User prompts the Orchestrator Agent regarding a task.</li><li>Orchestrator executes the Agent Information Action to discover the Helper Agents &amp; their Capability.</li><li>Using the output from the Agent Information Action, the Orchestrator breaks down the task into smaller sub-task which will be sent to the helper agents.</li><li>Helper Agent works on the sub-tasks and the output is returned back to the Orchestrator Agent. This happens in a cycle untill the end goal is achieved.</li><li>Once the Orchestrator achieves the end goal, the output is given to the User.</li></ol><p><strong>USE CASE CONSIDERATION:</strong></p><p>I considered a very simple use case of Case Management. I will have two agents:</p><ol><li>Case Creation Agent =&gt; Creates a Case based on User’s Input</li><li>Case Information Agent =&gt; Fetches the Case Details based on Case Number</li></ol><p>I took the Agents &amp; their associated Actions to be simple for the sake of this implementation.</p><p>My Orchestrator Agent will interact with the above agents to fulfill my Case related Requested.</p><p><strong>PRE-WORK:</strong></p><p>I have already configured the above helper agents as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3b4Aa-IENlrqWsPC6yN6Cw.png" /><figcaption>Case Fetch Agents with its Action &amp; Activated</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMpAwGAFkHUJj8ydHiHVBg.png" /><figcaption>Case Creation Agent with its Action &amp; Activated</figcaption></figure><p>In case you want a similar setup, you can clone my Github Repo containing the entire setup and deploy it to an Org with Agentforce.</p><p><a href="https://github.com/hari0409/A2A-Agentforce.git">GitHub - hari0409/A2A-Agentforce</a></p><p>With this we are ready to start working on our Orchestrator Agent.</p><p><strong>ORCHESTRATOR AGENT ACTION CONFIGURATION:</strong></p><p>We need to create two action:</p><ul><li>Agent Information Action</li><li>Prompt Agent Action</li></ul><p><strong>Agent Information Action:</strong></p><p><strong>Agent Information Action</strong> is an Apex defined action that will be used to retrieve information about the Agents &amp; their Available Actions. This can be then used by the Orchestrator Agent for planning &amp; execution.</p><p>Before we go for the Class, we need to understand how Salesforce Metadata stores these agent action:</p><p>Salesforce has the below Objects defined which has information about the Agent.</p><pre>GenAiFunctionDefinition   =&gt; Agent Action<br>GenAiPlannerDefinition    =&gt; Agent<br>GenAiPluginDefinition     =&gt; Topic<br>GenAiPlannerFunctionDef   =&gt; Junction between Agent &amp; Topic<br>GenAiPluginFunctionDef    =&gt; Junction between Topic &amp; Action <br>GenAiPluginInstructionDef =&gt; Instruction. </pre><p>Based on the above understanding I was able to write a class like below:</p><pre>public with sharing class AggregateAgentActions {<br>    @InvocableMethod(label = &#39;Get Helper Agent Action Information&#39; description = &#39;This can be used to get all the actions that are supported by the helper agents. This can be then used in future to determine which agent to call when.&#39;)<br>    public static List&lt;String&gt; getAgentActionMap(List&lt;AgentInputWrapper&gt; agentInputWrapper){<br>        List&lt;String&gt; agentAPINames = agentInputWrapper[0].agentAPINames;<br>        Set&lt;Id&gt; agentIds = new Set&lt;Id&gt;();<br>        Set&lt;Id&gt; topicIds = new Set&lt;Id&gt;();<br>        Set&lt;Id&gt; actionIds = new Set&lt;Id&gt;();<br>        Map&lt;Id, Set&lt;Id&gt;&gt; agentToTopicMap = new Map&lt;Id, Set&lt;Id&gt;&gt;();<br>        Map&lt;Id, Set&lt;Id&gt;&gt; topicToActionMap = new Map&lt;Id, Set&lt;Id&gt;&gt;();<br>        Map&lt;String,List&lt;GenAiFunctionDefinition&gt;&gt; allAgentInformation = new Map&lt;String,List&lt;GenAiFunctionDefinition&gt;&gt;();<br>        <br>        Map&lt;Id,GenAiPlannerDefinition&gt; agentDefinitions = new Map&lt;Id,GenAiPlannerDefinition&gt; ([SELECT Id, DeveloperName FROM GenAiPlannerDefinition WHERE DeveloperName IN :agentAPINames]);<br>        for(GenAiPlannerDefinition agentDef : agentDefinitions.values()){<br>            agentIds.add(agentDef.Id);<br>        }<br>        <br>        List&lt;GenAiPlannerFunctionDef&gt; agentTopicJuncs = [SELECT Id, PlannerId, Plugin FROM GenAiPlannerFunctionDef WHERE PlannerId IN :agentIds];<br>        for (GenAiPlannerFunctionDef agentTopicJunc : agentTopicJuncs) {<br>            topicIds.add(agentTopicJunc.Plugin);<br>            if (agentToTopicMap.containsKey(agentTopicJunc.PlannerId)){<br>                agentToTopicMap.get(agentTopicJunc.PlannerId).add(agentTopicJunc.Plugin);<br>            }else {<br>                agentToTopicMap.put(agentTopicJunc.PlannerId, new Set&lt;Id&gt;{agentTopicJunc.Plugin});<br>            }<br>        }<br>        <br>        List&lt;GenAiPluginFunctionDef&gt; actionTopicJunctions = [SELECT Id, PluginId, Function FROM GenAiPluginFunctionDef WHERE PluginId IN :topicIds];<br>        for(GenAiPluginFunctionDef actionTopicJunc:actionTopicJunctions){<br>            actionIds.add(actionTopicJunc.Function);<br>            if (topicToActionMap.containsKey(actionTopicJunc.PluginId)){<br>                topicToActionMap.get(actionTopicJunc.PluginId).add(actionTopicJunc.Function);<br>            }else {<br>                topicToActionMap.put(actionTopicJunc.PluginId, new Set&lt;Id&gt;{actionTopicJunc.Function});<br>            }<br>        }<br>        <br>        Map&lt;Id,GenAiFunctionDefinition&gt; actionDefinitions = new Map&lt;Id,GenAiFunctionDefinition&gt; ([SELECT MasterLabel, Description FROM GenAiFunctionDefinition WHERE Id IN :actionIds]);<br>        for(Id agentId:agentToTopicMap.keySet()){<br>            List&lt;GenAiFunctionDefinition&gt; actions = new List&lt;GenAiFunctionDefinition&gt;();<br>            Set&lt;Id&gt; agentSpecificTopics = agentToTopicMap.get(agentId);<br>            for (Id agentSpecificTopicId:agentSpecificTopics){<br>                Set&lt;Id&gt; agentSpecificActions = topicToActionMap.get(agentSpecificTopicId);<br>                if (agentSpecificActions!=null){<br>                    for (Id agentSpecificActionIds : agentSpecificActions){<br>                        actions.add(actionDefinitions.get(agentSpecificActionIds));<br>                    }<br>                }<br>            }<br>            allAgentInformation.put(agentDefinitions.get(agentId).DeveloperName, actions);<br>        }<br>        return new List&lt;String&gt;{JSON.serialize(allAgentInformation)};<br>    }<br>    <br>    public class AgentInputWrapper{<br>        @InvocableVariable(label = &#39;List of Agent API Name&#39; description = &#39;This is the list of all the Agent API Names which are present as helper agents to get their Action Information.&#39;)<br>        public List&lt;String&gt; agentAPINames;<br>    }<br>}</pre><p>On executing it via the Anonymous Window with the below script:</p><pre>AggregateAgentActions.AgentInputWrapper ipWrapper = new AggregateAgentActions.AgentInputWrapper();<br>ipWrapper.agentAPINames = new List&lt;String&gt;{&#39;Case_Creation_Agent&#39;,&#39;Case_Fetch_Agent&#39;}; // Can be your agent API Names<br>AggregateAgentActions.getAgentActionMap(new List&lt;AggregateAgentActions.AgentInputWrapper&gt;{ipWrapper});</pre><p>The output is as follows:</p><pre>{<br>   Case_Creation_Agent=(&quot;GenAiFunctionDefinition&quot;:{<br>      &quot;MasterLabel=Create Case Orchestration&quot;,<br>      &quot;Description=This action can be used to create a case for a given issue from the user.&quot;,<br>      Id=172fj00000BdkuHAAR<br>   }&quot;)&quot;,<br>   &quot;Case_Fetch_Agent=(GenAiFunctionDefinition&quot;:{<br>      &quot;MasterLabel=Get Case By Case Number Orchestration&quot;,<br>      &quot;Description=This can be used to get the Case Information for a given Case Number. Case Number is a required field for getting the case details.&quot;,<br>      Id=172fj00000BdfrNAAR<br>   }&quot;)&quot;<br>}</pre><p><strong>Prompt Agent Action:</strong></p><p>This is relatively simpler than the above Action as it just invoke the Agent for a given Prompt, Agent API Name &amp; Session Id.</p><pre>public with sharing class ApexAgentUtils {<br>    @InvocableMethod(label=&#39;Prompt Agent&#39; description = &#39;This can be used to prompt a Agent.&#39;)<br>    public static List&lt;String&gt; generateAgentOutput(List&lt;AgentInputWrapper&gt; agentInputWrapper){<br>        try{<br>            String prompt = agentInputWrapper[0].prompt;<br>            String sessionId = agentInputWrapper[0].sessionId;<br>            String agentAPIName = agentInputWrapper[0].agentAPIName;<br>            Invocable.Action action = Invocable.Action.createCustomAction(&#39;generateAiAgentResponse&#39;, agentAPIName);<br>            action.setInvocationParameter(&#39;userMessage&#39;, prompt);<br>            if (String.isNotEmpty(sessionId)){<br>                action.setInvocationParameter(&#39;sessionId&#39;, sessionId);<br>            }<br>            <br>            Invocable.Action.Result result = (action.invoke())[0];<br>            Map&lt;String, Object&gt; agentOutput = (Map&lt;String, Object&gt;) JSON.deserializeUntyped((String) result.getOutputParameters().get(&#39;agentResponse&#39;));<br>            Map&lt;String, String&gt; finalOutput = new Map&lt;String, String&gt;();<br>            finalOutput.put(&#39;agentResponse&#39;,(String) agentOutput.get(&#39;value&#39;));<br>            finalOutput.put(&#39;sessionId&#39;,(String) result.getOutputParameters().get(&#39;sessionId&#39;));<br>            return new List&lt;String&gt;{JSON.serialize(finalOutput)};<br>        }catch (Exception e){<br>            return new List&lt;String&gt;{&#39;Some Exception happened try again without any session id attached&#39;};<br>        }<br>    }<br>    <br>    public class AgentInputWrapper{<br>        @InvocableVariable(label = &#39;Prompt&#39; description = &#39;The prompt to be sent to interact with the agent&#39;)<br>        public String prompt;<br>        <br>        @InvocableVariable(label = &#39;SessionId&#39; description = &#39;The Session Id to maintain the context which was given as part of the previous interaction for this specific agent. If not present dont pass any value. Dont use session Id of another agent to another agent.&#39;)<br>        public String sessionId;<br>        <br>        @InvocableVariable(label = &#39;Agent API Name&#39; description = &#39;The API Name of the Agent with which you want to interact from the available set of Agent API Name given. Dont use imaginary API Names&#39;)<br>        public String agentAPIName;        <br>    }<br>}</pre><p>So here we are:</p><ul><li>Creating an instance of the Invocable Action and setting up the input parameters.</li><li>Setting up the Action with the required Input Paramters which includes userMessage &amp; sessionId</li><li>Then we invoke the Agent and the response is extracted &amp; sent back as output.</li></ul><p><strong>ORCHESTRATOR AGENT CONFIGURATION:</strong></p><p>Now that our actions are ready, we can start creating our agent. We can do so by:</p><ul><li>Setup &gt; Agentforce Agents &gt; New Agent</li><li>Choose the Type as <strong>Agentforce Employee Agents</strong></li><li>Remove the default General FAQ Topic (If selected)</li><li>Give it a Name, Description, Role &amp; Company</li><li>You can avoid the Agentforce Data Library Setup and Save it.</li></ul><p>Now we can create a topic for the Agent:</p><ul><li>Go to Topics &gt; New &gt; New Topics &gt; And configure the Topic with below information:</li></ul><pre>Name: Orchestration<br>Classification Description: This topic can be used to execute any given action because its not this current agent who will be performing the task. This topics contains Actions which gives you access to domain specific agents to whom you can send a prompt based on the user&#39;s prompt given to you. <br>Each Agent present in the Agent Actions has specific set of Activities that it can do and the output of the Activity of one agent can be used to invoke another agent for completing the entire action.<br>Scope: Your scope is limited to calling all the required agents via the Action and also chaining the actions if required to complete a given task.<br>Instructions:<br>  1. Available Agent&#39;s API Name are below: 1. Case_Creation_Agent 2. Case_Fetch_Agent <br>  2. Pass all the Agent API Name together in a single call to the Get Helper Agent Action Information Action to not call it again and again.<br>  3. Make sure the AgentInformation is not empty by calling Get Helper Agent Action Information Action. Make use of the AgentInformation Variable to determine which agent to call.  3. No generic response or response from other source are allowed.<br>  4. There will be multiple Action with each Action corresponding to an Agent to which you can send the prompt based on the user&#39;s need.<br>  5. You can also chain calls between multiple agents based on that task by invoking multiple actions each associated to a different agent based on the set of activities the child agents can do.<br>  6. If you get a valid output for a given input, dont converse anymore with the agent.</pre><ul><li>And Save it.</li></ul><p><strong>NOTE: </strong>We are configuring all the available Agents in the Instructions which will be used for the Agent Information Action to fetch Agent details. So this needs to be configured based on need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3F0MyYRqYXM79-GCJlh-A.png" /></figure><p>Agent Variable Configuration:</p><ul><li>Go to Context &gt; New Variable</li><li>Name &amp; API Name as <strong>AgentInformation</strong></li><li><strong>Description:</strong> This contains information about the Helper Agents &amp; their supported Actions which can be used to determine which agent to call and how to chain those calls.</li><li>Check Allow LLM to use value as <strong>True</strong></li><li>Save it.</li></ul><p>Configure the Agent Information Action:</p><ul><li>Go to the Orchestration Topic &gt; Topic’s Actions &gt; New Action</li><li>Choose the Reference Type as <strong>Apex</strong></li><li>Action Category: <strong>Invocable Method</strong></li><li>Choose the Reference Action as <strong>Get Helper Agent Action Information</strong></li><li>Configure the Action as below:</li><li><strong>Action Instruction:</strong> This can be used to get all the actions that are supported by the helper agents. This can be then used in future to determine which agent to call when. This needs to be executed when the AgentInformation is empty. If present make use of the value in AgentInformation for further processing.</li><li>Make <strong>Require Input as True</strong></li><li>Give the <strong>Output Instruction</strong> as</li></ul><pre>This contains all the agents &amp; their associated actions that are supported which can be used to determine which agent to call next.</pre><ul><li>Save it</li><li>After Saving it, navigate to the Action and map the output of the Action to the AgentInformation Variable.</li></ul><p>Configure the Prompt Agent Action:</p><ul><li>Go to Orchestration Topic &gt; Topic Action &gt; New Action</li><li>Choose the Reference Type as <strong>Apex</strong></li><li>Action Category: <strong>Invocable Action</strong></li><li>Choose the refrence Action as <strong>Prompt Action</strong></li><li>Configure the Action as below:</li><li>Make the <strong>Agent API Name &amp; Prompt </strong>as Require Input</li><li>Give the <strong>Output Instruction</strong> as</li></ul><pre>This is the response from the Agent which contains the below: <br>1. Agent Response <br>2. Agent Specific Session Id The Agent Specific Session Id can be used to interact with the same agent the next time if anything required. Or need not be passed to create a new session.</pre><p>Save it</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZEw6-Yi7oQCWccUE0vSiA.png" /></figure><p>With this the Orchestrator Agent is ready</p><p><strong>TESTING THE ORCHESTRATOR AGENT:</strong></p><p>I gave the prompt as below:</p><pre>Create a Case for the below issue:<br>Login Issue while using the Mobile App as Users say they are facing a 402 Issue<br>After creating, fetch details for the created case.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*575L80tazaSxrQhE04iXew.png" /></figure><p>Now the interesting part is analysing how the agent performed the action:</p><ul><li>First as instructed it fetched the Agent information:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*msKg2btc4PIni8b8f019dQ.png" /></figure><ul><li>Then using the Agent information it called the Case Creation Agent</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WWO1pt__LHwrkgE79j6L4Q.png" /></figure><ul><li>Then using the Case Number that have been returned by the Case Creation Agent, it called the Case Fetch Agent to get the case details:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MT3MHokrM2yNnvc9a7v7Ow.png" /></figure><ul><li>Then it consolidated the required output from the Agents &amp; gave it as the output to the User.</li></ul><p>So we can understand that for both the Interaction there was one common action used by the Orchestrator Agent to call the required helper agents.</p><p>We can also see that for a single request, it was also able to chain multiple request i.e., breaking down a complex task into small sub-task and execute them sequentially to get the desired output.</p><p><strong>CONCLUSION:</strong></p><p>So I hope it was an interesting article to read. There are a lot of potential limitation in my solution and a lot of places to improve which includes:</p><ul><li>Storing Session Information as variables rather than depending on the Atlas Reasoning Engine to remember it.</li><li>Way of storing the Helper Agent in the instruction in not a very good practices. Can you metadata to get the helper agents.</li></ul><p>And much more if you think depper. But I feel like for those issue, the core architecture wont change much and all of them can be fixed with some more accessory Actions &amp; variables. So cuz of feeling lazy on this Sunday mrg, I leave it upto you to improve it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b76234cd0e0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>