<?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 Gaurav Rawat on Medium]]></title>
        <description><![CDATA[Stories by Gaurav Rawat on Medium]]></description>
        <link>https://medium.com/@gaurav.rawat194?source=rss-d4aa5a998b65------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mhbaofT7jLceZq7F-2E5Dw.png</url>
            <title>Stories by Gaurav Rawat on Medium</title>
            <link>https://medium.com/@gaurav.rawat194?source=rss-d4aa5a998b65------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 09:05:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gaurav.rawat194/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[LWC: How to increase the size of Screen Action Modal Pop up in Salesforce CRM.]]></title>
            <link>https://medium.com/@gaurav.rawat194/lwc-how-to-increase-the-size-of-screen-action-modal-pop-up-in-salesforce-crm-2b6b2db34d82?source=rss-d4aa5a998b65------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b6b2db34d82</guid>
            <category><![CDATA[lightning-web-component]]></category>
            <category><![CDATA[button]]></category>
            <category><![CDATA[resize]]></category>
            <category><![CDATA[lightning-quick-action]]></category>
            <category><![CDATA[modal-popups]]></category>
            <dc:creator><![CDATA[Gaurav Rawat]]></dc:creator>
            <pubDate>Wed, 27 Sep 2023 18:10:21 GMT</pubDate>
            <atom:updated>2023-09-27T18:10:21.950Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Problem Statement: We have to implement a modal pop up that would open up based on button click event where it would show business data in the form of grid or other means.</strong></blockquote><blockquote>Design: There are numerous ways to implement this problem statement. I went for Lightning Web Components Quick Action: Screen Action.</blockquote><h3>What is Screen Action: It is an open modal popup window that shows some information when screen action button is clicked on Salesforce UI.</h3><blockquote><strong>Challenge: </strong>One of the challenges that I’ve faced is Screen Action are standard <strong>modal popup window in which its size i.e., height and width are fixed</strong>. We <strong>can’t really resize it simply by applying CSS</strong> straightaway to the component like we do it in vanilla JavaScript or jQuery.</blockquote><p>Let&#39;s follow along how I have implemented this problem statement and overcome the challenges —</p><p>Step 1: Create a LWC Component</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*TaleLdpIvnKHRArSknhnfA.png" /><figcaption>Lightning Web Component: SFDX Create Component</figcaption></figure><p>Step 2: Define Component Metadata</p><p>As we know, we are implementing LWC Quick Action i.e., Screen Action, hence, we need to define the metadata to expose it as Screen Action. We have set <strong>lightning_RecordAction target</strong> and specify <strong>action type as ScreenAction</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W0J_PSQr0oDTaCyRiwqD0Q.png" /><figcaption>Lightning Web Component: Screen Action Metadata</figcaption></figure><p>Step 3: Add Html markup to Component html file</p><p>I have added the html as an example because the main goal is to show how do I resolve the challenge along with implementing quick action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*76xpCPV-GgQwySNvCoqRXg.png" /><figcaption>Lightning Web Component: Html Markup</figcaption></figure><p>Step 4: Deploy the component</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*zSclgH2k8LtFNSmqSdG56g.png" /><figcaption>Lightning Web Component: SFDX Deploy to Org</figcaption></figure><p>Step 5: Create Screen Action in Opportunity</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bx_EdmSZ55s40u8TVFgqeQ.png" /><figcaption>Salesforce CRM: Create Action</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vyi2GT_QAw2KVPPUyYejpw.png" /><figcaption>Salesforce CRM: LWC Quick Action Screen Action Type</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YGcLRHl-NURI9Ye8szILFQ.png" /><figcaption>Salesforce CRM: LWC Opportunity Quick Action</figcaption></figure><p>Step 6: Add this Quick Action in Page layout</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z9mT6cPyX2jZW-brDH1zjA.png" /><figcaption>Opportunity: Page layout</figcaption></figure><p>Job isn’t finished yet; we have to add this Screen Action to the page layout as well. We have added this Action into Salesforce Mobile &amp; Lightning Experience Action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tTkWDmYszMVf1Km0YTu2sA.png" /><figcaption>Opportunity: Page layout</figcaption></figure><p>Step 7: Open Opportunity Record</p><p>Now, you have created the Action and could see the button over Opportunity Record.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ijxivC09MYT0q9wspt9Uxw.png" /><figcaption>Opportunity: Record</figcaption></figure><p>Step 8: Challenge is the modal size is fixed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qAOlf_tQCU7T1tWRgONQ2A.png" /><figcaption>LWC Quick Action: Fixed Size</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uboOSbjkzgJgbr4dXiH12w.png" /><figcaption>LWC Quick Screen Action: modal-container slds-modal__container classes</figcaption></figure><p>Step 9: How to resolve this issue?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*ZLyejbMJdigg5DecVkZaog.png" /><figcaption>Lightning Web Component: RenderedCallback LiveCycle hook</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9S-Wj8FhiPdM34duaFab6w.png" /><figcaption>Lightning Web Component: Quick Action Size Fixed</figcaption></figure><p>Hurray! We can really adjust the size of LWC Quick Screen Action. I hope this article will help you.</p><blockquote>A Big credit goes to Nikhil, Independent Salesforce Trainer from Udemy, he taught in one of his Zero to Hero Episodes “Styling across shadow DOM” in how to override standard CSS file which isn’t achievable normally by applying and overriding through CSS directly. Thanks to him, I have applied the same concepts over here.</blockquote><blockquote>Comment, Subscribe and follow to know more insights from Salesforce Topics.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b6b2db34d82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Salesforce Manufacturing Cloud: Salesforce Order Integration with MuleSoft]]></title>
            <link>https://medium.com/@gaurav.rawat194/salesforce-manufacturing-cloud-salesforce-order-integration-with-mulesoft-7a7a2403a18e?source=rss-d4aa5a998b65------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a7a2403a18e</guid>
            <category><![CDATA[mulesoft]]></category>
            <category><![CDATA[integration]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[manufacturing]]></category>
            <dc:creator><![CDATA[Gaurav Rawat]]></dc:creator>
            <pubDate>Mon, 03 Jul 2023 09:58:13 GMT</pubDate>
            <atom:updated>2023-07-14T07:54:28.791Z</atom:updated>
            <content:encoded><![CDATA[<h4>Explains how a company implement order management process in Salesforce Manufacturing Cloud with External system such as MuleSoft.</h4><blockquote>Use Case: Manufacturing Company has their existing systems in their on-premises App data server. They want to switch over to Salesforce Manufacturing Cloud as this Cloud was specifically designed for companies working in Manufacturing business ecosystem. The order management process in their existing system work like this — Customer sends orders 830 &amp; 862 (standard of EDI files) in Flat files format. ERP system takes those orders and outputs corresponding meaningful XML files, then these XML files are loaded as orders in their system through their application business Rules. Now, they want to simulate this process of order management in Salesforce ecosystem to check the feasibility of Salesforce Manufacturing Cloud.</blockquote><p>Our Solution: We have designed a process in MuleSoft which would simulate the process of taking Order information in XML file formats, then will be transformed into JSON format to load the Orders in Salesforce Manufacturing Cloud through Salesforce Apex REST API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Aq5wLSxg2OaC9NjrQ8M8Vg.png" /><figcaption>Salesforce MuleSoft Integration in Salesforce Manufacturing Cloud through Salesforce Apex REST Api</figcaption></figure><p>In this design, we have used MuleSoft Anypoint Studio to develop Process API (business process) which would take XML file from external systems, transformed that into JSON files. This Process API will then call System API (sub process) which would take this transformed JSON file and invoke Salesforce Apex Rest API through Salesforce connector module. This Salesforce Apex Rest API is a customized API written in Apex language &amp; hosted in Salesforce Manufacturing Cloud which would take JSON payload and perform some business logics to load (create or update Orders) inside Salesforce Manufacturing Cloud.</p><h4><strong>Pre-requisites:</strong></h4><ol><li>Create <a href="https://anypoint.mulesoft.com/login/signin?">Anypoint Platform Credentials</a> to manage and deploy the mulesoft projects to cloud hub.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*olMm3yKnfjqjozJcp3mkeA.png" /><figcaption>Anypoint Platform : Mulesoft</figcaption></figure><p>2. Setup Salesforce manufacturing cloud trial org, follow this trailhead module to setup your salesforce manufacturing cloud — <a href="https://trailhead.salesforce.com/content/learn/modules/manufacturing-cloud-admin-essentials/get-started-manufacturing-cloud#:~:text=In%20this%20module%2C%20we%20show%20you%20the%20steps,that%20contains%20Manufacturing%20Cloud%20and%20our%20sample%20data."><em>Get Started with Manufacturing Cloud Unit | Salesforce Trailhead</em></a></p><p>1st Step: Create new mule project named as ‘customerordertosalesforce’ and configure the settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lmfvR7RDVQlhWkpcu8R1Lw.png" /><figcaption>MuleSoft Anypoint Studio: Mule Project (System API)</figcaption></figure><p>Drop HTTP Listener module from mule palette and specify the connector configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*88XwJ63dOMy1EF-TZGJEig.png" /><figcaption>CustomerORderToSalesforce Mule Project : HTTP Listener Module</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*WsaNNe9kQ4BkiLLDlUoOZw.png" /><figcaption>CustomerOrderToSalesforce Mule Project : HTTP Listener Module Connector Configuration</figcaption></figure><p>Now, select MIME type as JSON as this API would be receiving JSON payload and loading them into Salesforce API to create/update Orders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BzHR2K5m-Npu8vMhA_pKRQ.png" /><figcaption>CustomerOrderToSalesforce Mule Project : HTTP Listener Module MIME TypeConfiguration</figcaption></figure><p>Define POST method as allowed methods for this API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*8ibNRGvie-V4j1YOv0Isbg.png" /><figcaption>CustomerOrderToSalesforce Mule Project : HTTP Listener Module Allowed Methods Configuration</figcaption></figure><p>Then drop Logger to log the payload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*db_M775X-R0E2Mz8MbKJUw.png" /><figcaption>CustomerOrderToSalesforce Mule Project : Logger module from Mule palette</figcaption></figure><p>Third, drop INVOKE APEX REST METHOD salesforce module from mule palette.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fDaS8hxIDJSPc8k8HJwaFw.png" /><figcaption>CustomerOrderToSalesforce Mule Project : Salesforce module from Mule palette</figcaption></figure><p>Now, configure the connection settings with salesforce from mulesoft. We are using Basic Authentication for simplicity where it will use integration user credentials to connect salesforce apex rest API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*yaHRFVQSB1ByBz6AvDa5Iw.png" /><figcaption>CustomerOrderToSalesforce Mule Project : Salesforce Connection Configuration</figcaption></figure><p>Once the connection is successfully tested using test connection option, add APEX class and respective API method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iuce65YB6Ix1Fn96jK6Aiw.png" /><figcaption>CustomerOrderToSalesforce Mule Project : Salesforce Apex Class Configuration</figcaption></figure><p>And that is it. We are done with creating this system API. Now, we will deploy this project as Mulesoft to Anypoint Cloudhub where it will give us public API URL endpoint so that we can use this URL while setting up the main Process API, another mulesoft API in 2nd Step.</p><blockquote>How to Deploy Mule Project to Anypoint Cloudhub ?</blockquote><p>Right click on the project, go to Anypoint platform and click Deploy to Cloudhub. It will ask for credentials, provide your credentials to deploy the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yrlgClj3OqzjiP7kzas-qA.png" /></figure><p>Once deployed, it would look like this —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NUmgLOLgSMJIkiVCDya1sA.png" /><figcaption>MuleSoft Anypoint Cloudhub Platform</figcaption></figure><p>2ndStep: Create new mule project named as ‘incomingorders’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*VuUxM2t0OZbdCOTN2dbtrg.png" /><figcaption>MuleSoft Anypoint Studio: Mule Project (Process API)</figcaption></figure><p>Drop HTTP Listener module in the canvas &amp; configure its properties as shown below —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FI66WBOe1I8DKumRZJSmRw.png" /><figcaption>IncomingOrders Mule Project : HTTP Listener Module</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*fA-BbysFGzBhp1byComBCQ.png" /><figcaption>IncomingOrders Mule Project: HTTP Listener Module Connection Settings</figcaption></figure><p>Select MIME type as application/xml.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*q6VbtWKMt4z8CAkQIYDnag.png" /><figcaption>IncomingOrder Mule project: HTTP Listener Module MIME Type</figcaption></figure><p>Select Allowed Method as POST so that it would accept POST method call to their API (process api).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*627xK6aOq761hUen3vCvDg.png" /><figcaption>IncomingOrder Mule project: HTTP Listener Module Advanced Setting</figcaption></figure><p>Next, drop Logger module in the canvas from Mulesoft palette.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a1Cie4TywFDRnhrPBJqM6Q.png" /><figcaption>IncomingOrder Mule project: Logger module configuration</figcaption></figure><p>Now, drop Transform Message Core module in the canvas which would take XML payload from previous step and convert it to JSON format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rDKGvddngJiLb8xnqmqxCw.png" /><figcaption>IncomingOrder Mule project: Transform Message Module</figcaption></figure><p>Here, in the input configuration, you can configure the input payload metadata by passing the XML dummy data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/518/1*aEsLocak106nYaqMkFEATw.png" /><figcaption>IncomingOrder mule project: Transform message module input payload metadata configuration</figcaption></figure><p>Right click on payload, &amp; chose Set Metadata option, Click Add new metadata type, name anything you want for the new type and click create type button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*wG3QE0OJqBQcsMEwzduwwQ.png" /><figcaption>IncomingOrder mule project: Transform Message Module Input payload Metadata</figcaption></figure><p>Create a XML file and paste this xml data in the file and save that file. Now, Select Type as XML, &amp; select option Example instead of Schema, &amp; provide the xml file —</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;Order&gt;<br> &lt;Sender&gt;<br>  &lt;LogicalId&gt;XYZ123&lt;/LogicalId&gt;<br>  &lt;Name&gt;Acme World&lt;/Name&gt;<br>  &lt;OrderNo&gt;00000428&lt;/OrderNo&gt;<br>  &lt;Agreement&gt;Acme Partner Purchases MFC&lt;/Agreement&gt;<br>  &lt;StartDate&gt;2023-06-04&lt;/StartDate&gt;<br>  &lt;EndDate&gt;&lt;/EndDate&gt;<br> &lt;/Sender&gt;<br> &lt;Lines&gt;<br>  &lt;Item&gt;<br>   &lt;LineNo&gt;0000001571&lt;/LineNo&gt;<br>   &lt;Name&gt;Compactor 8000&lt;/Name&gt;<br>   &lt;Quantity&gt;250&lt;/Quantity&gt;<br>   &lt;Discount&gt;5&lt;/Discount&gt;<br>  &lt;/Item&gt;<br>  &lt;Item&gt;<br>   &lt;LineNo&gt;0000001572&lt;/LineNo&gt;<br>   &lt;Name&gt;Hammer H500&lt;/Name&gt;<br>   &lt;Quantity&gt;500&lt;/Quantity&gt;<br>   &lt;Discount&gt;1&lt;/Discount&gt;<br>  &lt;/Item&gt;<br> &lt;/Lines&gt;<br>&lt;/Order&gt;</pre><p>Follow similar step for Output payload metadata, provide the JSON data corresponding the same XML file which you have saved earlier. Then map the fields from input payload to output payload by connecting the line from input field to output field.</p><h4><strong><em>JSON Dummy Data</em></strong></h4><pre>{<br> &quot;Order&quot;: {<br>  &quot;Sender&quot;: {<br>   &quot;LogicalId&quot;: &quot;XYZ123&quot;,<br>   &quot;Name&quot;: &quot;Acme World&quot;,<br>   &quot;OrderNo&quot;: &quot;00000428&quot;,<br>   &quot;Agreement&quot;: &quot;Acme Partner Purchases MFC&quot;,<br>   &quot;StartDate&quot;: &quot;2023-06-04&quot;,<br>   &quot;EndDate&quot;: &quot;Undefined&quot;<br>  },<br>  &quot;Lines&quot;: {<br>   &quot;Item&quot;: [{<br>     &quot;LineNo&quot;: &quot;0000001571&quot;,<br>     &quot;Name&quot;: &quot;Compactor 8000&quot;,<br>     &quot;Quantity&quot;: &quot;250&quot;,<br>     &quot;Discount&quot;: &quot;5&quot;<br>    },<br>    {<br>     &quot;LineNo&quot;: &quot;0000001572&quot;,<br>     &quot;Name&quot;: &quot;Hammer H500&quot;,<br>     &quot;Quantity&quot;: &quot;500&quot;,<br>     &quot;Discount&quot;: &quot;1&quot;<br>    }<br>   ]<br>  }<br> }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tsr4EPDKRa7Ap1kQB11l1Q.png" /><figcaption>IncomingOrder mule project: Transform Message Module Mapping Input &amp; output payload Configuration</figcaption></figure><p>When you map the fields, you will see on the right side, Output Payload code is automatically generated, you don’t need to explicitly right any code for mapping.</p><pre>%dw 2.0<br>output application/json<br>---<br>{<br> Order: {<br>  Sender: {<br>   LogicalId: payload.Order.Sender.LogicalId as String default &quot;Undefined&quot;,<br>   Name: payload.Order.Sender.Name as String default &quot;Undefined&quot;,<br>   OrderNo: payload.Order.Sender.OrderNo as String default &quot;Undefined&quot;,<br>   Agreement: payload.Order.Sender.Agreement as String default &quot;Undefined&quot;,<br>   StartDate: payload.Order.Sender.StartDate as String default &quot;Undefined&quot;,<br>   EndDate: payload.Order.Sender.EndDate as String default &quot;Undefined&quot;<br>  },<br>  Lines: {<br>   Item: payload.Order.Lines.*Item map ( item , indexOfItem ) -&gt; {<br>    LineNo: item.LineNo as String default &quot;Undefined&quot;,<br>    Name: item.Name as String default &quot;Undefined&quot;,<br>    Quantity: item.Quantity as String default &quot;Undefined&quot;,<br>    Discount: item.Discount as String default &quot;Undefined&quot;<br>   }<br>  }<br> }<br>}</pre><p>Now, once transform message configuration is done, drop the logger again to validate the output of transformation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SiVpqQ3Hc-G7eAwCjP5Iqw.png" /><figcaption>IncomingOrder mule project: Logger Module</figcaption></figure><p>Next, drop HTTP Request module in the canvas which would get configure to call sub-mulesoft API whose job is to take transformed json output from transform message module and call invoke api rest api call from salesforce.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uQyMsZVHGi-D7FHB7lOXHA.png" /><figcaption>IncomingOrder mule project: HTTP Request module General Configuration</figcaption></figure><p>Set the configuration to Request module, here in basic settings, configure the endpoint URL to call other mulesoft api, method as POST.</p><p>Set Connection settings as it is —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*ruH0gmwDr3iZkQkhvx7ejQ.png" /><figcaption>IncomingOrder mule project: HTTP Request module Connection settings Configuration</figcaption></figure><p>Set MIME type as application/json.</p><p>Now, last but not the least, again drop the logger to the canvas to log the response from API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iz7WB6XUzqx85cXjNhGQgQ.png" /><figcaption>IncomingOrder mule project: Logger Module</figcaption></figure><p>Now, deploy the mule project by following these steps: -</p><ol><li>Right click on incoming order project</li><li>Click on Anypoint Platform</li><li>Deploy to Cloud hub</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66dSDcH9o3yRajaTfbFm7A.png" /><figcaption>IncomingOrder mule project: Deploy to Anypoint Cloudhub</figcaption></figure><p>You will see your two mulesoft APIs hosted in Anypoint Cloudhub platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bT8BrYUPRNyB4h-u6oCofQ.png" /><figcaption>MuleSoft Anypoint Cloudhub Platform</figcaption></figure><p>The next thing is to test your mulesoft APIs via POSTMAN.</p><h4><strong>MuleSoft Process API (IncomingOrder)</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cb80Z7jqFgQc_geDfoxdiQ.png" /><figcaption>POSTMAN: Mulesoft API Demonstration</figcaption></figure><h4><strong>MuleSoft System API (CustomOrderToSalesforce)</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28cavSAEklco6Ms-UIVkSQ.png" /><figcaption>POSTMAN: Mulesoft API Demonstration</figcaption></figure><p>Salesforce Manufacturing Cloud APEX REST API Code —</p><h3><strong>LoadOrderApi Class</strong></h3><pre>@RestResource(urlMapping=&#39;/order/*&#39;)<br>global without sharing class LoadOrdersApi { <br>        <br>    public class ErrorResponse {<br>        public String message;<br>    }<br>    <br>    @HttpPost<br>    global static void loadOrder(){<br>        RestRequest req = RestContext.request;<br>  <br>        String jsonRequestPayload=req.requestBody.toString();<br>        // Deserialize the JSON payload using the wrapper class<br>        LoadOrderWrapperClass orderWrapper= LoadOrderWrapperClass.parse(jsonRequestPayload);    <br>        System.debug(&#39;@@@@ orderWrapper  &#39; +orderWrapper);<br>        ErrorResponse response = new ErrorResponse();<br>        <br>        // Extract the order information from the wrapper class<br>        LoadOrderWrapperClass.Sender senderInfo = orderWrapper.Order.Sender;<br>        LoadOrderWrapperClass.Lines linesInfo = orderWrapper.Order.Lines;<br>        <br>        // Check if the order already exists in Salesforce based on the order number<br>        String orderNumber = senderInfo.OrderNo;<br>        Order existingOrder=null;<br>        if(orderNumber!= &#39;Undefined&#39;){<br>        existingOrder = OrderService.getOrderByOrderNumber(orderNumber);<br>        System.Debug(&#39;@@@@&#39;+ existingOrder);<br>        }<br>        List&lt;Account&gt; Accounts=OrderService.getAccountsByName(senderInfo.Name);<br>        if(Accounts.size()==0){<br>            System.debug(&#39;@@@@ Account null&#39;);            <br>            String errorMessage = &#39;Customer has no Account found in salesforce to create or update the order&#39;;<br>            RestContext.response = OrderHandler.getRestResponse(response,errorMessage);            <br>            return;<br>        }        <br>        List&lt;SalesAgreement&gt; salesAgreement = OrderService.getSalesAgreementByAccountNameAndSenderInfoAgreement(senderInfo.Agreement,Accounts[0].id);<br><br>        if(salesAgreement.size()==null){<br>            System.debug(&#39;@@@@ SA null &#39;);<br>            String errorMessage = &#39;Customer has no sales agreement found in salesforce&#39;;<br>            RestContext.response = OrderHandler.getRestResponse(response,errorMessage);<br>            return;<br>        }<br>        <br>        // get products details and add them to list<br>        <br>        List&lt;string&gt; prodNamesFromPayload = new List&lt;string&gt;();<br>        for(LoadOrderWrapperClass.Item productsFromPayload: linesInfo.Item){<br>            prodNamesFromPayload.add(productsFromPayload.Name);<br>        }<br>        <br>        Map&lt;Id, Product2&gt; productsDetails = new Map&lt;Id, Product2&gt;(OrderService.getProductsBySenderLineItemsName(prodNamesFromPayload)); <br>        System.debug(productsDetails);<br>        System.debug(productsDetails.values());            <br>        // Some products aren&#39;t added as part of migration activity from business<br>        if(productsDetails.size()!=linesInfo.Item.size()){<br>            System.debug(&#39;@@@@ Products error &#39;);<br>            String errorMessage = &#39;Products are not found in Salesforce Platform, Please load the products first.&#39;;<br>            RestContext.response = OrderHandler.getRestResponse(response,errorMessage);           <br>            return;<br>        }<br>        <br>        Map&lt;Id, PricebookEntry&gt; priceBookEntryDetails = new Map&lt;Id, PricebookEntry&gt;(OrderService.getPriceBookEntriesByPriceBookIdAndSenderLineItemsName(salesAgreement[0].PricebookId,prodNamesFromPayload));<br>        System.debug(priceBookEntryDetails);<br>        System.debug(priceBookEntryDetails); <br>        <br>        if (existingOrder != null ) {<br>            // Update the existing line items            <br>            List&lt;OrderItem&gt; lineItems = OrderHandler.updateLineItems(existingOrder, linesInfo.Item, productsDetails, priceBookEntryDetails);<br>            // Update the line items in Salesforce<br>            Database.UpsertResult[] lineItemUpdateResults = Database.upsert(lineItems, false);<br>            for (Database.UpsertResult result : lineItemUpdateResults) {<br>                if (!result.isSuccess()) {<br>                    String errorMessage = result.getErrors()[0].getMessage(); <br>                    RestContext.response = OrderHandler.getRestResponse(response,errorMessage);                  <br>                    return;<br>                }<br>            }<br>            OrderApiResponse.SuccessResponse successResponse = OrderHandler.setOrderApiResponseByOrderAndOrderItems(existingOrder, lineItems, &#39;Order Updated&#39;); <br>            existingOrder.Status = &#39;Activated&#39;;<br>            update existingOrder;            <br>            RestResponse res = RestContext.response;<br>            res.responseBody = Blob.valueOf(JSON.serialize(successResponse));<br>            res.statusCode = 200;<br>        } else {<br>            <br>            // Create a new Order record<br>            System.debug(&#39;@@@@ new order Creation block&#39;);<br>            Order newOrder = OrderHandler.CreateOrder(Accounts[0], salesAgreement[0], senderInfo);<br>                      <br>            Database.SaveResult orderInsertResult = Database.insert(newOrder, false);<br>            if (!orderInsertResult.isSuccess()) {<br>                System.debug(&#39;@@@@ Order error &#39;);<br>                String errorMessage = orderInsertResult.getErrors()[0].getMessage(); <br>                RestContext.response = OrderHandler.getRestResponse(response,errorMessage);              <br>                return;<br>            }<br>            <br>            List&lt;OrderItem&gt; items = OrderHandler.CreateLineItems(newOrder, linesInfo.Item, productsDetails,priceBookEntryDetails);<br>            // Insert the new line items into Salesforce<br>         Database.SaveResult[] lineItemInsertResults = Database.insert(items, false);<br>  <br>            for (Database.SaveResult result : lineItemInsertResults) {<br>                if (!result.isSuccess()) {<br>                    System.debug(&#39;@@@@@ line item error &#39;);<br>                    String errorMessage = result.getErrors()[0].getMessage(); <br>                    RestContext.response = OrderHandler.getRestResponse(response,errorMessage);                    <br>                    return;<br>                }<br>            }            <br>            OrderApiResponse.SuccessResponse successResponse = OrderHandler.setOrderApiResponseByOrderAndOrderItems(newOrder, items, &#39;Order Created&#39;);                                            <br>            RestResponse res = RestContext.response;<br>            res.responseBody = Blob.valueOf(JSON.serialize(successResponse));<br>            res.statusCode = 200;            <br>        }<br>    }      <br>}</pre><h3><strong>LoadOrderWrapper Class</strong></h3><pre>public class LoadOrderWrapperClass {<br>  public class Order {<br>  public Sender Sender {get;set;} <br>  public Lines Lines {get;set;} <br><br>  public Order(JSONParser parser) {<br>   while (parser.nextToken() != System.JSONToken.END_OBJECT) {<br>    if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {<br>     String text = parser.getText();<br>     if (parser.nextToken() != System.JSONToken.VALUE_NULL) {<br>      if (text == &#39;Sender&#39;) {<br>       Sender = new Sender(parser);<br>      } else if (text == &#39;Lines&#39;) {<br>       Lines = new Lines(parser);<br>      } else {<br>       System.debug(LoggingLevel.WARN, &#39;Order consuming unrecognized property: &#39;+text);<br>       consumeObject(parser);<br>      }<br>     }<br>    }<br>   }<br>  }<br> }<br>    <br>    public class Sender {<br>  public String LogicalId {get;set;} <br>  public String Name {get;set;} <br>  public String OrderNo {get;set;} <br>  public String Agreement {get;set;} <br>  public String StartDate {get;set;} <br>  public String EndDate {get;set;} <br><br>  public Sender(JSONParser parser) {<br>   while (parser.nextToken() != System.JSONToken.END_OBJECT) {<br>    if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {<br>     String text = parser.getText();<br>     if (parser.nextToken() != System.JSONToken.VALUE_NULL) {<br>      if (text == &#39;LogicalId&#39;) {<br>       LogicalId = parser.getText();<br>      } else if (text == &#39;Name&#39;) {<br>       Name = parser.getText();<br>      } else if (text == &#39;OrderNo&#39;) {<br>       OrderNo = parser.getText();<br>      } else if (text == &#39;Agreement&#39;) {<br>       Agreement = parser.getText();<br>      } else if (text == &#39;StartDate&#39;) {<br>       StartDate = parser.getText();<br>      } else if (text == &#39;EndDate&#39;) {<br>       EndDate = parser.getText();<br>      } else {<br>       System.debug(LoggingLevel.WARN, &#39;Sender consuming unrecognized property: &#39;+text);<br>       consumeObject(parser);<br>      }<br>     }<br>    }<br>   }<br>  }<br> }<br> <br> public class Item {<br>  public String LineNo {get;set;} <br>  public String Name {get;set;} <br>  public String Quantity {get;set;} <br>  public String Discount {get;set;} <br><br>  public Item(JSONParser parser) {<br>   while (parser.nextToken() != System.JSONToken.END_OBJECT) {<br>    if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {<br>     String text = parser.getText();<br>     if (parser.nextToken() != System.JSONToken.VALUE_NULL) {<br>      if (text == &#39;LineNo&#39;) {<br>       LineNo = parser.getText();<br>      } else if (text == &#39;Name&#39;) {<br>       Name = parser.getText();<br>      } else if (text == &#39;Quantity&#39;) {<br>       Quantity = parser.getText();<br>      } else if (text == &#39;Discount&#39;) {<br>       Discount = parser.getText();<br>      } else {<br>       System.debug(LoggingLevel.WARN, &#39;Item consuming unrecognized property: &#39;+text);<br>       consumeObject(parser);<br>      }<br>     }<br>    }<br>   }<br>  }<br> }<br> <br> public Order Order {get;set;} <br><br> public LoadOrderWrapperClass(JSONParser parser) {<br>  while (parser.nextToken() != System.JSONToken.END_OBJECT) {<br>   if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {<br>    String text = parser.getText();<br>    if (parser.nextToken() != System.JSONToken.VALUE_NULL) {<br>     if (text == &#39;Order&#39;) {<br>      Order = new Order(parser);<br>     } else {<br>      System.debug(LoggingLevel.WARN, &#39;JSON2Apex consuming unrecognized property: &#39;+text);<br>      consumeObject(parser);<br>     }<br>    }<br>   }<br>  }<br> }<br> <br> public class Lines {<br>  public List&lt;Item&gt; Item {get;set;} <br><br>  public Lines(JSONParser parser) {<br>   while (parser.nextToken() != System.JSONToken.END_OBJECT) {<br>    if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {<br>     String text = parser.getText();<br>     if (parser.nextToken() != System.JSONToken.VALUE_NULL) {<br>      if (text == &#39;Item&#39;) {<br>       Item = arrayOfItem(parser);<br>      } else {<br>       System.debug(LoggingLevel.WARN, &#39;Lines consuming unrecognized property: &#39;+text);<br>       consumeObject(parser);<br>      }<br>     }<br>    }<br>   }<br>  }<br> }<br>  <br> public static LoadOrderWrapperClass parse(String json) {<br>  System.JSONParser parser = System.JSON.createParser(json);<br>  return new LoadOrderWrapperClass(parser);<br> }<br> <br> public static void consumeObject(System.JSONParser parser) {<br>  Integer depth = 0;<br>  do {<br>   System.JSONToken curr = parser.getCurrentToken();<br>   if (curr == System.JSONToken.START_OBJECT || <br>    curr == System.JSONToken.START_ARRAY) {<br>    depth++;<br>   } else if (curr == System.JSONToken.END_OBJECT ||<br>    curr == System.JSONToken.END_ARRAY) {<br>    depth--;<br>   }<br>  } while (depth &gt; 0 &amp;&amp; parser.nextToken() != null);<br> }<br><br>    private static List&lt;Item&gt; arrayOfItem(System.JSONParser p) {<br>        List&lt;Item&gt; res = new List&lt;Item&gt;();<br>        if (p.getCurrentToken() == null) p.nextToken();<br>        while (p.nextToken() != System.JSONToken.END_ARRAY) {<br>            res.add(new Item(p));<br>        }<br>        return res;<br>    }<br>}</pre><h3><strong>OrderHandler Class</strong></h3><pre>public without sharing class OrderHandler {<br>    public static Order CreateOrder(Account existingAccount, SalesAgreement existingSalesAgreement, LoadOrderWrapperClass.Sender senderInfo){<br>        Order newOrder = new Order();                  <br>        newOrder.AccountId=existingAccount.Id;        <br>        newOrder.SalesAgreementId = existingSalesAgreement.id;<br>        newOrder.Pricebook2Id = existingSalesAgreement.PricebookId;<br>        newOrder.EffectiveDate = Date.valueOf(senderInfo.StartDate);<br>        newOrder.Pricebook2Id=existingSalesAgreement.PricebookId;<br>        newOrder.Status = &#39;Draft&#39;; // Set default status<br>        return newOrder;<br>    }<br>    <br>    public static List&lt;OrderItem&gt; CreateLineItems(Order order,List&lt;LoadOrderWrapperClass.Item&gt; lineItemsInfo,<br>                                                  Map&lt;Id,Product2&gt; prodDetails,Map&lt;Id,PricebookEntry&gt; priceBookEntryDetails){<br>                                                      List&lt;OrderItem&gt; newLineItems = new List&lt;OrderItem&gt;();                                                              <br>                                                      for (LoadOrderWrapperClass.Item lineItemInfo : lineItemsInfo) {<br>                                                          OrderItem newItem = new OrderItem();<br>                                                          for(Product2 product : prodDetails.values()){<br>                                                              if(product.Name ==lineItemInfo.Name){<br>                                                                  newItem.Product2Id=product.Id;<br>                                                              }<br>                                                          }            <br>                                                          for(PricebookEntry priceBookEntry : priceBookEntryDetails.values()){<br>                                                              if(priceBookEntry.Name ==lineItemInfo.Name){<br>                                                                  newItem.PricebookEntryId=priceBookEntry.Id;<br>                                                                  newItem.UnitPrice = priceBookEntry.UnitPrice;<br>                                                              }<br>                                                          }                                                                               <br>                                                          newItem.OrderId = order.Id;                                                          <br>                                                          newItem.Quantity =Decimal.Valueof(lineItemInfo.Quantity);<br>                                                          newItem.Discount__c = Decimal.Valueof(lineItemInfo.Discount);                                                          <br>                                                          newLineItems.add(newItem);<br>                                                      }<br>                                                      return newLineItems;<br>                                                  }<br>    <br>    public static List&lt;OrderItem&gt; updateLineItems(Order order, List&lt;LoadOrderWrapperClass.Item&gt; lineItemsInfo,<br>                                        Map&lt;Id,Product2&gt; prodDetails,Map&lt;Id,PricebookEntry&gt; priceBookEntryDetails) {                                            <br>                                            List&lt;OrderItem&gt; existingLineItems = [SELECT id,OrderId,Product2Id,Discount__c,Quantity,OrderItemNumber,Product2.Name FROM OrderItem <br>                                                                                 WHERE OrderId = :order.Id];<br>                                                                                                                                    <br>                                            Map&lt;String, OrderItem&gt; existingLineItemsMap = new Map&lt;String, OrderItem&gt;();<br>                                            for (OrderItem item : existingLineItems) {<br>                                                existingLineItemsMap.put(String.valueOf(item.OrderItemNumber), item);<br>                                            }<br>                                                                                        <br>                                            List&lt;OrderItem&gt; updatedLineItems = new List&lt;OrderItem&gt;();<br>                                            for (LoadOrderWrapperClass.Item lineItemInfo : lineItemsInfo) {<br>                                                String lineNumber = lineItemInfo.LineNo;           <br>                                                if (existingLineItemsMap.containsKey(lineNumber)) {<br>                                                    // existing line items<br>                                                    OrderItem existingItem = existingLineItemsMap.get(lineNumber);                                                       <br>                                                    existingItem.Quantity =Decimal.Valueof(lineItemInfo.Quantity);<br>                                                    existingItem.Discount__c = Decimal.Valueof(lineItemInfo.Discount);                                                                                                                                                        <br>                                                    updatedLineItems.add(existingItem);<br>                                                } else {<br>                                                    // Create a new line items<br>                                                    OrderItem newItem = new OrderItem();   <br>                                                    <br>                                                    for(Product2 product : prodDetails.values()){<br>                                                        if(product.Name ==lineItemInfo.Name){<br>                                                            newItem.Product2Id=product.Id;<br>                                                        }<br>                                                    }            <br>                                                    for(PricebookEntry priceBookEntry : priceBookEntryDetails.values()){<br>                                                        if(priceBookEntry.Name ==lineItemInfo.Name){<br>                                                            newItem.PricebookEntryId=priceBookEntry.Id;<br>                                                            newItem.UnitPrice = priceBookEntry.UnitPrice;<br>                                                        }<br>                                                    }                                           <br>                                                    newItem.OrderId = order.Id;                <br>                                                    newItem.Quantity =Decimal.Valueof(lineItemInfo.Quantity);<br>                                                    newItem.Discount__c = Decimal.Valueof(lineItemInfo.Discount); <br>                                                    updatedLineItems.add(newItem);<br>                                                }<br>                                            }                                                    <br>                                            return updatedLineItems;<br>                                            <br>                                        }<br>    public static OrderApiResponse.SuccessResponse setOrderApiResponseByOrderAndOrderItems(Order newOrder, List&lt;OrderItem&gt; items, string msg){<br>        Order orderWithOrderNumber = OrderService.getOrderByOrderId(newOrder.Id);<br>            OrderApiResponse.SuccessResponse successResponse = new OrderApiResponse.SuccessResponse();<br>            OrderApiResponse.SfOrder sfOrder = new OrderApiResponse.SfOrder();<br>            sfOrder.orderno = orderWithOrderNumber.OrderNumber;<br>            sfOrder.orderstatus = newOrder.Status;<br>            <br>            List&lt;OrderApiResponse.SfOrderLineItem&gt; lineItems=new List&lt;OrderApiResponse.SfOrderLineItem&gt;();<br>            Set&lt;Id&gt; lineIds = new Set&lt;Id&gt;();<br>            for(OrderItem item: items){<br>                lineIds.add(item.Id);                <br>            }<br>            List&lt;OrderItem&gt; orderLineItems = OrderService.getLineItemsByLineItemIds(lineIds);<br>            for(OrderItem item: orderLineItems){<br>                OrderApiResponse.SfOrderLineItem lItem = new OrderApiResponse.SfOrderLineItem();<br>                lItem.lineno = item.OrderItemNumber;<br>                lItem.prodname = item.Product2.Name;<br>                lineItems.add(lItem);<br>            }            <br>            sfOrder.lineitems = lineItems;<br>         successResponse.message = msg;<br>            successResponse.sforder = sfOrder;<br>        return successResponse;<br>    }<br>    <br>    public static RestResponse getRestResponse(LoadOrdersApi.ErrorResponse errResponse, string errMsg){<br>        RestResponse response = RestContext.response;<br>        errResponse.message = errMsg; <br>        response.statusCode = 400;<br>        response.responseBody = Blob.valueOf(JSON.serialize(errResponse));<br>        return response;<br>    }<br>}</pre><h3><strong>OrderService Class</strong></h3><pre>public without sharing class OrderService {<br>    public static Order getOrderByOrderNumber(string orderNumber){<br>        return [SELECT Id,OrderNumber, Status FROM Order WHERE Status &lt;&gt; &#39;Activated&#39; AND OrderNumber = :orderNumber LIMIT 1];<br>    }<br>    public static List&lt;Account&gt; getAccountsByName(string senderInfoName){<br>        return [SELECT Id,Name FROM account WHERE Name = :senderInfoName LIMIT 1];<br>    }<br>    public static List&lt;SalesAgreement&gt; getSalesAgreementByAccountNameAndSenderInfoAgreement(string agreement, Id id){<br>        return [SELECT Id,PricebookId FROM SalesAgreement WHERE Name = :agreement AND AccountId = :id AND Status =&#39;Activated&#39; LIMIT 1];<br>    }<br>    public static List&lt;Product2&gt; getProductsBySenderLineItemsName(List&lt;string&gt; prodNamesFromPayload){<br>        return [Select Id,Name from Product2 where Name IN :prodNamesFromPayload];<br>    }<br>    public static List&lt;PricebookEntry&gt; getPriceBookEntriesByPriceBookIdAndSenderLineItemsName(Id id, List&lt;string&gt; prodNamesFromPayload){<br>        return [Select Id,Name,UnitPrice from PricebookEntry where Pricebook2.Id= :id AND Name IN :prodNamesFromPayload];<br>    }<br>    public static Order getOrderByOrderId(Id orderId){<br>        return [Select Id, OrderNumber from Order where Id= :orderId];<br>    }<br>    public static List&lt;OrderItem&gt; getLineItemsByLineItemIds(Set&lt;Id&gt; lineIds){<br>        return [Select Id,OrderItemNumber,Product2Id,Product2.Name from OrderItem where Id IN :lineIds];<br>    }    <br>}</pre><h3><strong>OrderApiResponse Class</strong></h3><pre>public class OrderApiResponse {<br> public class SuccessResponse{<br>        public SfOrder sforder;<br>        public string message;<br>    }<br>    public class SfOrder{<br>        public string orderno;<br>        public string orderstatus; <br>        public List&lt;SfOrderLineItem&gt; lineitems;<br>    }<br>    public class SfOrderLineItem{<br>        public string lineno;<br>        public string prodname;        <br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SeuAEsR6Z3YOUGAI89tDjA.png" /><figcaption>MuleSoft Integration with Salesforce Manufacturing Cloud via POSTMAN (mimic as ERP Data Source)</figcaption></figure><p>This is it. Hope this article could help you. Share your thoughts too, how could I improve further.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a7a2403a18e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Salesforce Manufacturing Cloud]]></title>
            <link>https://medium.com/@gaurav.rawat194/salesforce-manufacturing-cloud-176f5040112c?source=rss-d4aa5a998b65------2</link>
            <guid isPermaLink="false">https://medium.com/p/176f5040112c</guid>
            <category><![CDATA[sales-agreement]]></category>
            <category><![CDATA[salesforce-flow]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[manufacturing]]></category>
            <category><![CDATA[opportunity]]></category>
            <dc:creator><![CDATA[Gaurav Rawat]]></dc:creator>
            <pubDate>Thu, 08 Jun 2023 07:31:50 GMT</pubDate>
            <atom:updated>2023-06-08T07:31:50.217Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to convert Opportunities to Sales Agreements?</h4><p>We will learn how for a Manufacturing business or client (Manufacturer) who is using Salesforce cloud such as Sales cloud can be migrated to beautiful Salesforce Industry solution i.e., Manufacturing Cloud. The Salesforce Manufacturing Cloud cater all the needs of Manufacturing Industry where it helps you manage your entire book-of-business and customer service lifecycle, while increasing collaboration and transparency between sales, operations, and partners.</p><blockquote>In this article, <strong>we will convert the existing opportunities to Manufacturing Cloud Sales Agreements</strong>. Sales Agreements help your key account managers plan for sales and operations better by enabling sales agreements in your org. Key account managers can use sales agreements to negotiate business transactions.</blockquote><p>There are multiple ways to convert existing opportunities to Sales Agreements —</p><ol><li>Use Lightning Flow to convert existing Opportunities to Sales Agreements.</li><li>Use Apex Code to convert existing Opportunities to Sales Agreements.</li><li>Use Metadata API to convert existing Opportunities to Sales Agreements.</li></ol><p>I will be explaining Lightning flow here to convert existing Opportunities to Sales Agreements.</p><blockquote>Use Case — Convert All opportunities that are closed won to Sales Agreements.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N_2ryQGrwWWbkP0WZBTn6w.png" /><figcaption>Lightning flow: Convert Opportunity to Sales Agreements</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*yw3cEnxBoLQ-vuIza5LRAg.png" /><figcaption>Flow Resources</figcaption></figure><p><strong>Record Single Variables</strong></p><ol><li>SalesAgreementObject — This record variable is used to hold a Sales Agreement Object required to create record.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*7db1mwVRkPwSIEbG_Hp53g.png" /></figure><p>2. SalesAgreementProductVar- This record variable is used to hold a Sales Agreement Product Object required to create record.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*uFzuAVXQiNcOQgXWKjAqOA.png" /><figcaption>Record Single Variable: SalesAgreementProductVar</figcaption></figure><p><strong>Record Collection Variables</strong></p><ol><li>OpportunityProductsVar — This record collection variable is used to hold list of Opportunity Line Items records.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*SfQW8AenHFc2iYL32bRflw.png" /><figcaption>Record Collection Variable: OpportunityProductsVar</figcaption></figure><p>2. SalesAgreementProductsVar- This record collection is used to hold list of Sales Agreement Product records i.e., SalesAgreementProductVar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*pAhn1rvyr9g_LR4bJ1RmNQ.png" /><figcaption>Record Collection Variable: SalesAgreementProductsVar</figcaption></figure><p>I have implemented Schedule flow (act as job) that will run daily, fetches the opportunities that are in closed won stage and then map the fields data from opportunity and opportunity Line items to Sales Agreement and Sales Agreement Products. The overall implementation is worked like as described below —</p><p>1st Step is to define start criteria when to schedule this flow and also the object on which it will trigger. Frequency will be daily. Object is Opportunity and the conditions are stage name should be closed won, pricebook shouldn’t be null, &amp; converted status should be false.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L26uPsl_ae5JzZtKJxoHyg.png" /></figure><p>Why I took pricebook as entry criteria condition is because if we want to create Sales Agreement, then pricebook is the mandatory field to mention. Without price book why can’t create Sales Agreement.</p><p>Also, this Converted__c field, I have created it as custom field inside Opportunity so that after converting the opportunity, we can set this field to true which means opportunity have been converted. Also, it will solve the issue of considering the opportunity record again to convert. Using this flag, those opportunity records cannot be considered again.</p><p>2nd Step is to map opportunity record into record variable SalesAgreementObject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWa5l6mksmE5tIton1Gtnw.png" /><figcaption>Assignment: Map Opportunity fields to SA</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*pJle3bbVlN2fm1yU9c9HVg.png" /><figcaption>Assignment: Map Opportunity fields to SA</figcaption></figure><p>3rd Step is to create Sales Agreement Object record that is mapped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vHk-0k5RlQMplHhd5Zr2BQ.png" /><figcaption>Create Record: Create Sales Agreement</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*MD7TFDDMRUoasIQUQ9WSCQ.png" /><figcaption>Create Record: Create Sales Agreement</figcaption></figure><p>4th Step is used to get all Opportunity Line Items that are associated with Opportunity record and stored them in record collection variable i.e., OpportunityProductsVar. We are storing limited fields in this object because only these fields values are needed to create Sales Agreement Product record.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q42QiZVUz9DSyi7lf8avXw.png" /><figcaption>Get Records: Get Opp Line Items</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fxb-hYDJuKBVcu88RMDS7g.png" /><figcaption>Get Records: Get Opp Line Items</figcaption></figure><p>5th Step is used to iterate through Opportunity Line items records that are retrieved and stored in previous step inside this collection OpportunityProductsVar variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SBrTLH9bAQGqGqCFTvY6NQ.png" /><figcaption>Loop: Loop through Opp Products Collection</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*ON3iUWe6_hOZhTHf8hOK6Q.png" /><figcaption>Loop: Loop through Opp Products Collection</figcaption></figure><p>6th Step is used to map fields values coming from loop variable to record variable i.e., SalesAgreementProductVar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wnvrRraqPQZBKO7hrygfYw.png" /><figcaption>Assignment: Map Opp Products Fields to SA Product</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*68w53HzF7mH3Mqn2Gv0d3A.png" /><figcaption>Assignment: Map Opp Products Fields to SA Product</figcaption></figure><p><em>Mapping fields</em> -</p><p><strong>OppProducts.TotalPrice -&gt; SalesAgreementProduct.InitialPlannedAmount<br>OP.OpportunityProductName -&gt; SA.Name<br>OP.ProductID -&gt; SA.ProductID<br>OP.PriceBookEntryID -&gt; SA.PriceBookEntryID<br>OP.Quantity -&gt; SA.InitialTotalQuantity</strong></p><p>Last but not the least, in order to map Sales Agreement Id in Sales Agreement Product record, we map this ID from record variable <strong>SalesAgreementObject.SalesAgreementID</strong> because Opportunity don’t have any association with Sales Agreement &amp; we need Sales Agreement ID which we created in <strong><em>Step 3</em></strong>.</p><p>7th Step is used to add the record mapped to the list. Here we have added the record variable SalesAgreementProductVar which was mapped in previous step 6 to the record collection variable SalesAgreementProductsVar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0FWN66FRVBNRRm3StuKDsQ.png" /><figcaption>Assignment: Add SA Product To Collection</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*0HIpZ6LSlsZ1DqcEZAyVpQ.png" /><figcaption>Assignment: Add SA Product to Collection</figcaption></figure><p>8th Step is used to create Sales Agreement Products from record collection variable SalesAgreementProductsVar that have all the mapped Sales Agreement Products records built from previous step 7.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YQs8AgFdum5c6oBcx7d4Ug.png" /><figcaption>Create Record: Create Sales Agreement Products</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*wDLXxvJbZ4dtj2edIHus0Q.png" /><figcaption>Create Record: Create Sales Agreement Products</figcaption></figure><p>9th Step is used to set the flag of Opportunity record that is converted to True state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8dl-3DYqtFsdiCTMijwYOw.png" /><figcaption>Update Record: Update Opportunity To Converted</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*gU8meXmaau2FLY53GLALRg.png" /><figcaption>Update Record: Update Opportunity to Converted</figcaption></figure><p>This is it. Hope this article can help. Share your thoughts too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=176f5040112c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>