<?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 Jagmohan Singh on Medium]]></title>
        <description><![CDATA[Stories by Jagmohan Singh on Medium]]></description>
        <link>https://medium.com/@jagmohan.singh.1?source=rss-366403654d57------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5VPd5Gh_y578uEG2SiJJtA.jpeg</url>
            <title>Stories by Jagmohan Singh on Medium</title>
            <link>https://medium.com/@jagmohan.singh.1?source=rss-366403654d57------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:06:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jagmohan.singh.1/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[Visualforce Remoting Exception: Collection is read-only]]></title>
            <link>https://medium.com/@jagmohan.singh.1/visualforce-remoting-exception-collection-is-read-only-4b50b9bc6771?source=rss-366403654d57------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b50b9bc6771</guid>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[visualforce]]></category>
            <category><![CDATA[lightning-web-component]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[aura]]></category>
            <dc:creator><![CDATA[Jagmohan Singh]]></dc:creator>
            <pubDate>Tue, 13 May 2025 13:01:38 GMT</pubDate>
            <atom:updated>2025-05-13T13:01:38.279Z</atom:updated>
            <content:encoded><![CDATA[<p>When using Visualforce/JavaScript Remoting, collections passed to methods annotated with @RemoteAction are read-only and cannot be modified directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LwQfKGzYxY5DUgLl" /><figcaption>Photo by <a href="https://unsplash.com/@aaronburden?utm_source=medium&amp;utm_medium=referral">Aaron Burden</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When working with Visualforce Remoting in Salesforce, a common and frustrating error developers may run into is:</p><pre>System.TypeException: Collection is read-only</pre><p>This typically occurs when trying to <strong>modify a collection (like a Map or List) that was passed into an Apex method annotated with </strong><strong>@RemoteAction</strong> from a Visualforce page.</p><h4>The Problem</h4><p>Consider the following Apex method:</p><pre>@RemoteAction<br>public static void processData(Map&lt;String, String&gt; inputMap) {<br>    inputMap.remove(&#39;someKey&#39;); // Throws &quot;Collection is read-only&quot;<br>}</pre><p>Even though the code compiles correctly and seems will work just fine, calling remove on inputMap will throw a System.TypeException with the message: <em>Collection is read-only</em>.</p><h4>Why This Happens</h4><p>When Visualforce passes data from JavaScript to Apex via Remoting, <strong>the collections (Maps, Lists) are deserialized into read-only objects</strong>. This ensures that the original data passed from the client remains unchanged.</p><p>Because of this, <strong>any attempt to add, remove, or modify elements directly in the passed collection will fail</strong>.</p><h4>Workaround</h4><p>To work around this, <strong>create a modifiable copy</strong> of the collection before making changes:</p><pre>@RemoteAction<br>public static void processData(Map&lt;String, String&gt; inputMap) {<br>    // Create a new Map and copy the contents<br>    Map&lt;String, String&gt; localCopy = new Map&lt;String, String&gt;(inputMap);<br>    // Now safe to modify<br>    localCopy.remove(&#39;someKey&#39;);<br>    // your logic which works with localCopy map<br>}</pre><p>This approach allows you to safely manipulate the data as needed without hitting the read-only exception.</p><h3>Final Thoughts</h3><ul><li>Collections passed to Apex <strong>@RemoteAction</strong> methods from JavaScript are <strong>read-only</strong>.</li><li>Attempting to modify such collections directly will throw a <strong>System.TypeException</strong>.</li><li>Always copy the collection into a new instance before modifying it.</li></ul><p>You can follow me on <a href="https://medium.com/@jagmohan.singh.1">Medium</a> or <a href="https://x.com/JagmohanPadam">X</a> for upcoming posts related to Apex, Lightning Web Components, Agentforce and Salesforce platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b50b9bc6771" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating Meme Generation in Salesforce with Prompt Builder, Flow and Apex]]></title>
            <link>https://medium.com/@jagmohan.singh.1/automating-meme-generation-in-salesforce-with-prompt-builder-flow-and-apex-8bf8067c1d63?source=rss-366403654d57------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bf8067c1d63</guid>
            <category><![CDATA[meme-generator]]></category>
            <category><![CDATA[salesforce-flow]]></category>
            <category><![CDATA[prompt-engineering]]></category>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[integration]]></category>
            <dc:creator><![CDATA[Jagmohan Singh]]></dc:creator>
            <pubDate>Mon, 28 Apr 2025 13:02:40 GMT</pubDate>
            <atom:updated>2025-04-28T13:02:40.091Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<p>Recently, I tried a small experiment: <strong>Automatically generate and post a meme when an Opportunity is Closed Lost.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rHEAWhEhMFgqXc-z" /><figcaption>Photo by <a href="https://unsplash.com/@thommilkovic?utm_source=medium&amp;utm_medium=referral">Thom Milkovic</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Here is exactly how I did it.</p><p><strong>Step 1: Create a Prompt Template</strong></p><p>I started with Prompt Builder and created a <strong>Field Generation</strong> prompt template that takes in Opportunity fields (like Name, Stage Amount, Close Date) and generates a <strong>humorous meme caption</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1tDfMOyF_S4eKVIGI-HpUA.png" /><figcaption>Field Generation Prompt Template using Opportunity Fields</figcaption></figure><p>The idea: make losing an opportunity a little lighter with humor.</p><p><strong>Step 2: Build a Flow</strong></p><p>I built an <strong>autolaunched flow </strong>and which runs when an <strong>Opportunity</strong> is <strong>Closed Lost</strong>.</p><p>Inside the flow:</p><ul><li>Call the Prompt Builder to run the prompt using Opportunity data.</li><li>Output: <strong>meme text.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*4vh9G9UA0gabYuzWXr2REw.png" /><figcaption>Salesforce Flow To Run Prompt and Call Apex Action</figcaption></figure><p>In the above flow, you will notice that I have used a Scheduled Path. This is because we can not make a callout to an external endpoint in the <strong>Run Immediately</strong> flow path. I have set the <strong>Scheduled Path</strong> run after 1 minute of the record update.</p><p><strong>Step 3: Generate a Meme Image using Apex</strong></p><p>Next, I passed the meme text to an Apex Invocable Method.</p><p>The Apex class:</p><ul><li>Calls the Imgflip API</li><li>Sends the meme text</li><li>Gets back a meme image URL</li></ul><pre>public with sharing class GenerateMemeAction {<br><br>    public class Request {<br>        @InvocableVariable(label=&#39;Opportunity Id&#39; required=true)<br>        public Id opportunityId;<br><br>        @InvocableVariable(label=&#39;Meme Text JSON&#39; required=true)<br>        public String memeTextJson;<br>    }<br><br>    public class Response {<br>        @InvocableVariable(label=&#39;Meme URL&#39;)<br>        public String memeUrl;<br>    }<br><br>    @InvocableMethod(callout=true label=&#39;Generate Meme from Opportunity&#39;)<br>    public static List&lt;Response&gt; generate(List&lt;Request&gt; requests) {<br>        List&lt;Response&gt; results = new List&lt;Response&gt;();<br><br>        List&lt;FeedItem&gt; feedItems = new List&lt;FeedItem&gt;();<br>        for (Request req : requests) {<br>            try {<br>                Map&lt;String, Object&gt; memeText = (Map&lt;String, Object&gt;)JSON.deserializeUntyped(req.memeTextJson);<br><br>                String topText = (String) memeText.get(&#39;text0&#39;);<br>                String bottomText = (String) memeText.get(&#39;text1&#39;);<br><br>                String memeUrl = MemeService.createMeme(topText, bottomText);<br>                // Create Chatter Post<br>                String postText = topText + &#39; &#39; + bottomText;<br>                feedItems.add(postToChatter(req.opportunityId, postText, memeUrl));<br><br>                Response res = new Response();<br>                res.memeUrl = memeUrl;<br>                results.add(res);<br>            } catch (Exception e) {<br>                System.debug(&#39;Error generating meme: &#39; + e.getMessage());<br>                results.add(new Response());<br>            }<br>        }<br>        // save chatter posts<br>        insert feedItems;<br>        return results;<br>    }<br>    <br>    private static FeedItem postToChatter(Id parentId, String postText, String imageUrl) {<br>        FeedItem post = new FeedItem();<br>        post.ParentId = parentId;<br>        post.Body = postText + &#39;\n\n [Meme](&#39; + imageUrl + &#39;)&#39;;<br>        post.Type = &#39;TextPost&#39;;<br>        return post;<br>    }<br>}</pre><pre>public class MemeService {<br><br>    private static final Set&lt;String&gt; TEMPLATE_IDS = new Set&lt;String&gt;{<br>        &#39;181913649&#39;, &#39;112126428&#39;, &#39;87743020&#39;, &#39;124822590&#39;, &#39;129242436&#39;, &#39;438680&#39;, &#39;217743513&#39;, &#39;131087935&#39;, <br>        &#39;61579&#39;, &#39;93895088&#39;, &#39;4087833&#39;, &#39;102156234&#39;, &#39;1035805&#39;, &#39;97984&#39;, &#39;188390779&#39;, &#39;91538330&#39;, &#39;101470&#39;, <br>        &#39;247375501&#39;, &#39;131940431&#39;, &#39;89370399&#39;, &#39;222403160&#39;, &#39;119139145&#39;, &#39;61520&#39;, &#39;178591752&#39;, &#39;155067746&#39;, <br>        &#39;114585149&#39;, &#39;5496396&#39;, &#39;135256802&#39;, &#39;27813981&#39;, &#39;80707627&#39;, &#39;100777631&#39;, &#39;123999232&#39;, &#39;21735&#39;, <br>        &#39;61532&#39;, &#39;148909805&#39;, &#39;226297822&#39;, &#39;124055727&#39;, &#39;28251713&#39;, &#39;252600902&#39;, &#39;161865971&#39;, &#39;8072285&#39;, <br>        &#39;61585&#39;, &#39;101288&#39;, &#39;134797956&#39;, &#39;61539&#39;, &#39;180190441&#39;, &#39;110163934&#39;, &#39;91545132&#39;, &#39;61556&#39;, &#39;6235864&#39;, <br>        &#39;175540452&#39;, &#39;84341851&#39;, &#39;3218037&#39;, &#39;61544&#39;, &#39;61527&#39;, &#39;55311130&#39;, &#39;14371066&#39;, &#39;135678846&#39;, &#39;563423&#39;, <br>        &#39;61546&#39;, &#39;79132341&#39;, &#39;196652226&#39;, &#39;405658&#39;, &#39;61582&#39;, &#39;16464531&#39;, &#39;61533&#39;, &#39;101511&#39;, &#39;195515965&#39;, <br>        &#39;1509839&#39;, &#39;99683372&#39;, &#39;235589&#39;, &#39;101287&#39;, &#39;259237855&#39;, &#39;61516&#39;, &#39;100947&#39;, &#39;14230520&#39;, &#39;132769734&#39;, <br>        &#39;245898&#39;, &#39;922147&#39;, &#39;101910402&#39;, &#39;101716&#39;, &#39;61580&#39;, &#39;101440&#39;, &#39;40945639&#39;, &#39;109765&#39;, &#39;259680&#39;, <br>        &#39;9440985&#39;, &#39;61581&#39;, &#39;29617627&#39;, &#39;163573&#39;, &#39;56225174&#39;, &#39;12403754&#39;, &#39;21604248&#39;, &#39;460541&#39;, &#39;195389&#39;, <br>        &#39;1367068&#39;, &#39;6531067&#39;, &#39;766986&#39;, &#39;444501&#39;, &#39;100955&#39;<br>    };<br><br>    public class MemeResponse {<br>        public Boolean success;<br>        public MemeData data;<br>    }<br>    <br>    public class MemeData {<br>        public String url;<br>        public String page_url;<br>    }<br><br>    public static String createMeme(String topText, String bottomText) {<br>        Http http = new Http();<br>        HttpRequest request = new HttpRequest();<br><br>        request.setEndpoint(&#39;https://api.imgflip.com/caption_image&#39;);<br>        request.setMethod(&#39;POST&#39;);<br>        request.setHeader(&#39;Content-Type&#39;, &#39;application/x-www-form-urlencoded&#39;);<br><br>        // Replace with your Imgflip username and password<br>        String username = &#39;USE_YOUR_USERNAME&#39;;<br>        String password = &#39;USE_YOUR_PASSWORD&#39;;<br>        List&lt;String&gt; templateList = new List&lt;String&gt;(TEMPLATE_IDS);<br>        Integer randomIndex = Math.mod(Math.abs(Crypto.getRandomInteger()), templateList.size());<br>        String templateId = templateList.get(randomIndex);<br>        String body = &#39;template_id=&#39; + EncodingUtil.urlEncode(templateId, &#39;UTF-8&#39;) +<br>                      &#39;&amp;username=&#39; + EncodingUtil.urlEncode(username, &#39;UTF-8&#39;) +<br>                      &#39;&amp;password=&#39; + EncodingUtil.urlEncode(password, &#39;UTF-8&#39;) +<br>                      &#39;&amp;text0=&#39; + EncodingUtil.urlEncode(topText, &#39;UTF-8&#39;) +<br>                      &#39;&amp;text1=&#39; + EncodingUtil.urlEncode(bottomText, &#39;UTF-8&#39;);<br>        <br>        request.setBody(body);<br>        HttpResponse response = http.send(request);<br><br>        if (response.getStatusCode() == 200) {<br>            MemeResponse memeRes = (MemeResponse) JSON.deserialize(response.getBody(), MemeResponse.class);<br>            if (memeRes.success) {<br>                return memeRes.data.url;<br>            } else {<br>                throw new CalloutException(&#39;Imgflip API returned failure.&#39;);<br>            }<br>        } else {<br>            throw new CalloutException(&#39;Failed to call Imgflip API: &#39; + response.getBody());<br>        }<br>    }<br>}</pre><p><em>Note: </em>When you try to run code in your Salesforce Org, please make sure to create a <strong>Remote Site Setting</strong> for the Imgflip API. This is code snippet can be further improved by using a <strong>Named Credential</strong> as well.</p><p><strong>Step 4: Post the Meme to Chatter</strong></p><p>Finally, I used standard Chatter post logic in Apex:</p><ul><li>Upload the meme image</li><li>Post it to the related Opportunity’s Chatter feed</li></ul><h3>Results</h3><p>Every time an Opportunity is Closed Lost, the system automatically posts a <strong>custom meme</strong> on the Opportunity’s Chatter feed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tJAXSZ_deSeSBHlWKQGx-w.png" /></figure><p>No manual effort. Adds a bit of humor to the sales process.</p><h3>Final Thoughts</h3><p>This was a quick experiment, but it showed how easy it is to:</p><ul><li>Use <strong>Prompt Builder</strong> for real-world automation.</li><li>Combine <strong>Flow</strong> + <strong>Apex</strong> to call external APIs.</li><li>Make Salesforce processes more human and fun.</li></ul><p>You can follow me on <a href="https://medium.com/@jagmohan.singh.1">Medium</a> or <a href="https://x.com/JagmohanPadam">X</a> for upcoming posts related to Apex, Lightning Web Components, Agentforce and Salesforce platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bf8067c1d63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Custom Lightning Component for Alert and Confirm Dialogs]]></title>
            <link>https://blog.cloudanswers.com/create-a-custom-lightning-component-for-alert-and-confirm-dialogs-c5316b8fc434?source=rss-366403654d57------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5316b8fc434</guid>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[salesforce-lightning]]></category>
            <dc:creator><![CDATA[Jagmohan Singh]]></dc:creator>
            <pubDate>Sat, 09 Mar 2024 03:04:31 GMT</pubDate>
            <atom:updated>2025-04-26T11:24:47.350Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bRjBdNG_OzI2w_SSx6L2cQ.gif" /></figure><p>As front-end developers, there can be numerous instances when we need to display a prompt, a confirm dialog, or a confirm dialog with some input control to accept some value from the user. If you happen to be a Salesforce developer reading this article, you must have had such a requirement while writing lightning components.</p><p>There are a couple of components available in the <a href="https://developer.salesforce.com/docs/component-library">Lightning Components Library</a> that can be used to render dialogs.</p><h4><a href="https://developer.salesforce.com/docs/component-library/bundle/lightning:overlayLibrary/documentation">lightning:lightning:overlayLib</a></h4><p>This component is quite extensive and offers good flexibility for rendering the dialog header, body, etc. However, this component lacks:</p><ol><li>Ability to accept input from the user</li><li>Support for Lightning Out</li></ol><h4><a href="https://developer.salesforce.com/docs/component-library/bundle/lightning:alert/example">lightning:alert</a> and <a href="https://developer.salesforce.com/docs/component-library/bundle/lightning:confirm">lightning:confirm</a></h4><p>This component is supported in both Lightning Experience and Lightning Out but lacks</p><ol><li>Ability to accept input from a user</li><li>Ability to override header, body, etc to render HTML markup</li></ol><h4>Workaround</h4><p>As a workaround for the missing features in the above components, I have put together a custom Lightning component that supports</p><ol><li>Accepting input from a user</li><li>Rendering HTML markup in modal body</li><li>Both Lightning Experience and Lightning Out</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ab9527421703d0dfaf46cedebbc5516/href">https://medium.com/media/9ab9527421703d0dfaf46cedebbc5516/href</a></iframe><p>Let us understand the basics of this component. This component exposes an <a href="https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_tag_method.htm"><strong>aura:method</strong></a><strong> </strong>that accepts a configuration object. We can pass various configuration attributes to make the component behave as:</p><ol><li>Alert dialog</li><li>Confirm dialog (Yes / No)</li><li>Confirm dialog with text input</li></ol><p>Let us look into the configuration for some popular use cases.</p><h4>Add CustomAlert Component</h4><p>The first step is to add this component to our Lightning component. We can do that by adding the following line of code to our lightning component.</p><pre>&lt;c:CustomAlert aura:id=”custom-alert” /&gt;</pre><h4>Display an info message</h4><p>There are numerous instances where we just want to display an info message and also want the user to take note of it by blocking the user interface. Instead of using the standard JavaScript alert dialog, we can use this component to display an alert dialog matching the Lightning Experience UI. Plus, this component offers the ability to render markup in the message body.</p><pre>var customAlert = component.find(&#39;custom-alert&#39;);<br>customAlert.open({<br>    title: &#39;Info!&#39;,<br>    message: &#39;This modal contains some info message&#39;,<br>    confirmButtonLabel: &#39;OK&#39;,<br>    showConfirmButton: true,<br>    showCancelButton: false,<br>    promptType: &#39;info&#39;,<br>    callbackFn: function(result, userInput) {<br>        console.log(result, userInput);<br>    }<br>});</pre><h4>Prompt the user to confirm an action</h4><p>Many times, we need the user to confirm the action which is going to take place to make sure the user hasn’t initiated the action accidentally. The most common place for such confirmation dialogs is when the delete button is clicked. Here is the configuration for that scenario:</p><pre>var customAlert = component.find(&#39;custom-alert&#39;);<br>customAlert.open({<br>    title: &#39;Confirm Delete&#39;,<br>    message: &#39;Do you want to delete selected record?&#39;,<br>    confirmButtonLabel: &#39;Yes&#39;,<br>    cancelButtonLabel: &#39;No&#39;,<br>    showCancelButton: true,<br>    promptType: &#39;warning&#39;,<br>    callbackFn: function(result, userInput) {<br>        console.log(result, userInput);<br>        if (result == true) {<br>            // perform desired action<br>        }<br>    }<br>});</pre><p>The key thing to note here is the <strong>callbackFn</strong> function attribute. This function accepts two parameters.</p><ol><li><em>result</em>: The value of this parameter is used to identify whether the user has confirmed the action or not. If its value is true, then it means the user has confirmed the action, any other value means the user cancelled the action.</li><li><em>userInput</em>: We will see how this parameter is used in the next use case.</li></ol><h4>Accept input from the user</h4><p>Sometimes, we come across a scenario where we need some input from the user before completing an action. In such cases, we can make use of this component to display a prompt with an input field. The user enters a value, clicks the confirm action button, and proceeds to complete the action. Here is how we can display such a confirm dialog:</p><pre>var customAlert = component.find(&#39;custom-alert&#39;);<br>customAlert.open({<br>    title: &#39;Success&#39;,<br>    confirmButtonLabel: &#39;Confirm&#39;,<br>    cancelButtonLabel: &#39;Cancel&#39;,<br>    showCancelButton: true,<br>    inputType: &#39;text&#39;,<br>    inputLabel: &#39;Enter Name&#39;,<br>    inputPlaceholder: &#39;Please enter your name&#39;,<br>    promptType: &#39;success&#39;,<br>    callbackFn: function(result, inputValue) {<br>        console.log(result, inputValue);<br>        if (result == true) {<br>            // proceed with desired action with input from user<br>        }<br>    }<br>});</pre><p>In the previous use case, we saw that the callbackFn function accepts two parameters. We saw the first param is used to denote whether the confirm or cancel button was clicked. The second param comes into play when we are accepting input from the user, whatever user enters, is passed into this param.</p><h4>Conclusion</h4><p>The main reason for building the CustomAlert component was to overcome the limitations in the standard alert/confirm Lightning components. Hopefully, Salesforce will release updates to the standard components to add the missing features. Until then, we can use this component as a workaround.</p><p>The original <a href="https://cloudanswers.com/blog/create-a-custom-lighting-component">article</a> was published on our website. If you found this helpful, please don’t hold back your upvotes, and you can follow us on <a href="https://www.linkedin.com/company/cloudanswers">LinkedIn</a> for more tips and tricks related to Apex, Visualforce, Aura, Lightning Web Components, and the Salesforce platform.</p><p>If you need any help with Salesforce or have something a little more complex that might require some advanced developer knowledge, you can chat with us at <a href="https://cloudanswers.com/?utm_source=Medium&amp;utm_medium=article&amp;utm_term=Server_side_pagination_using_Apex&amp;utm_content=CloudAnswers_website">https://cloudanswers.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5316b8fc434" width="1" height="1" alt=""><hr><p><a href="https://blog.cloudanswers.com/create-a-custom-lightning-component-for-alert-and-confirm-dialogs-c5316b8fc434">Create a Custom Lightning Component for Alert and Confirm Dialogs</a> was originally published in <a href="https://blog.cloudanswers.com/">CloudAnswers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Custom Component to Update Experience Cloud Profile Photos]]></title>
            <link>https://blog.cloudanswers.com/creating-a-custom-component-to-update-experience-cloud-profile-photos-f4be4beda387?source=rss-366403654d57------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4be4beda387</guid>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[salesforce-productivity]]></category>
            <category><![CDATA[salesforce-communities]]></category>
            <category><![CDATA[apex]]></category>
            <dc:creator><![CDATA[Jagmohan Singh]]></dc:creator>
            <pubDate>Tue, 10 Oct 2023 15:02:04 GMT</pubDate>
            <atom:updated>2023-10-10T15:02:04.199Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*byIVS_87xMp_uowzzYvvJQ.gif" /></figure><p>Are you looking for a lightning component to set or update a community user’s profile photo? If yes, please read this article for a guide that makes it simple.</p><p>A profile photo adds a personal touch to the profile and helps others easily identify the person behind the profile. In the context of professional profiles, a profile photo can convey competence and seriousness. Also, people tend to trust profiles with photos more than those without it. So, most often than not, you will come across a requirement to allow the user to be able to update their profile photo like we did while building a custom profile page for one of our customers.</p><p>For building this component, we would need three methods:</p><ol><li>Set Community User Profile Photo</li><li>Get Community User Profile Photo</li><li>Delete Community User Profile Photo</li></ol><h4>Set Community User Profile Photo</h4><p>The UserProfiles class under the ConnectApi namespace provides various methods to set, get and delete a user’s profile photo. Let’s look at one such method, <a href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_ConnectAPI_UserProfiles_static_methods.htm#apex_ConnectAPI_UserProfiles_setPhoto_2">setPhoto</a>.</p><pre>public static ConnectApi.Photo setPhoto(String communityId, String userId, ConnectApi.BinaryInput fileUpload)</pre><p>This method accepts three parameters:</p><ol><li><em>communityId</em>: This is the Id of the community to which the user is logged in. We can obtain this Id using the Network.getNetworkId method.</li><li><em>userId</em>: This is the Id of logged in user. We can obtain this using the UserInfo.getUserId() method.</li><li><em>fileUpload</em>: This should be an object of ​​ConnectApi.BinaryInput class containing the Blob data, content type and name for image.</li></ol><h4>Get Community User Profile Photo</h4><p>Let us say you are building a custom profile page for Experience or Community Cloud users in Salesforce and you want to display a user’s profile photo. Here is how you can get the info about a user’s profile photo which can be used to render their profile photo.</p><p>The getPhoto method from UserProfiles class under ConnectApi namespace can be used to get the user profile photo.</p><pre>public static ConnectApi.Photo getPhoto(String communityId, String userId)</pre><p>This method accepts two parameters:</p><ol><li><em>communityId</em>: This is the Id of the community to which the user is logged in. We can obtain this Id using the Network.getNetworkId method.</li><li><em>userId</em>: This is the Id of logged in user. We can obtain this using the UserInfo.getUserId() method.</li></ol><h4>Delete Community User Profile Photo</h4><p>You have seen how you can set and get a community user photo. There can be multiple reasons when a user would need to delete their profile photo. For e.g: due to change in Organization’s compliance and security policies users may be required to remove their profile photos. So now, you may be wondering how you can allow your users to be able to delete their profile photo from the custom page you built. You’re in luck, we have that answer as well!</p><p>We can use the deletePhoto method from the UserProfiles class under ConnectApi for deleting the profile photo.</p><pre>public static Void deletePhoto(String communityId, String userId)</pre><p>This method accepts two parameters:</p><ol><li><em>communityId</em>: This is the Id of the community to which the user is logged in. We can obtain this Id using the Network.getNetworkId method.</li><li><em>userId</em>: This is the Id of logged in user. We can obtain this using the UserInfo.getUserId() method.</li></ol><h4>Putting It Together in Apex class</h4><p>Here is the Apex class which contains all the methods to get, set and delete photos.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b960b78a746393491d747adef6248241/href">https://medium.com/media/b960b78a746393491d747adef6248241/href</a></iframe><p>The output of <em>getCommunityUserPhoto</em> of the above method would look something like this:</p><pre>{<br> &quot;photo&quot;: {<br>  &quot;fullEmailPhotoUrl&quot;: &quot;some_url&quot;,<br>  &quot;largePhotoUrl&quot;: &quot;some_url&quot;,<br>  &quot;mediumPhotoUrl&quot;: &quot;some_url&quot;,<br>  &quot;photoVersionId&quot;: &quot;photo_version_id&quot;,<br>  &quot;smallPhotoUrl&quot;: &quot;some_url&quot;,<br>  &quot;standardEmailPhotoUrl&quot;: &quot;some_url&quot;,<br>  &quot;url&quot;: &quot;some_url&quot;<br> },<br> &quot;status&quot;: true<br>}</pre><p>You can use smallPhotoUrl, mediumPhotoUrl or largePhotoUrl in the src attribute of image tag to render the user profile photo.</p><h4>Custom Lightning Component and Apex Controller</h4><p>You can find the full source code for Lightning component and Apex class in this <a href="https://gist.github.com/jagmohansingh/d2cf5cc758b05f459d37e4291b9628c6">GitHub Gist</a>.</p><p>If you found this helpful, please don’t hold back your upvotes and you can follow me on <a href="https://medium.com/@jagmohan.singh.1">Medium</a> or <a href="https://twitter.com/JagmohanSingh">Twitter</a> for more tips and tricks related to Apex, Visualforce, Aura, Lightning Web Components and Salesforce platform.</p><p>If you need any help with Salesforce or have something little more complex that might require some advanced developer knowledge, you can contact us at <a href="/service/mailto:help@cloudanswers.com">help@cloudanswers.com</a> or chat with us on <a href="https://cloudanswers.com/?utm_source=Medium&amp;utm_medium=article&amp;utm_term=Server_side_pagination_using_Apex&amp;utm_content=CloudAnswers_website">https://cloudanswers.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4be4beda387" width="1" height="1" alt=""><hr><p><a href="https://blog.cloudanswers.com/creating-a-custom-component-to-update-experience-cloud-profile-photos-f4be4beda387">Creating a Custom Component to Update Experience Cloud Profile Photos</a> was originally published in <a href="https://blog.cloudanswers.com/">CloudAnswers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to describe an SObject in Apex]]></title>
            <link>https://medium.com/@jagmohan.singh.1/how-to-describe-an-sobject-in-apex-a428dedd158?source=rss-366403654d57------2</link>
            <guid isPermaLink="false">https://medium.com/p/a428dedd158</guid>
            <category><![CDATA[salesforce-lightning]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[visualforce]]></category>
            <category><![CDATA[apex]]></category>
            <dc:creator><![CDATA[Jagmohan Singh]]></dc:creator>
            <pubDate>Wed, 09 Nov 2022 05:30:42 GMT</pubDate>
            <atom:updated>2022-11-09T05:30:42.166Z</atom:updated>
            <content:encoded><![CDATA[<p>There are many instances when we want to describe an SObject in Apex for e.g. we want to get a list of all the fields for an object which are accessible to the logged in user. We can use any of the following options depending on our use case.</p><p><strong>Using the sObjectType property on SObject</strong></p><p>Let’s say we just want to an instance of DescribeSObjectResult for the Account object. We can use the sObjectType property of the Account object and call the getDescribe method to get an instance DescribeSObjectResult.</p><pre>DescribeSObjectResult objResult = Account.sObjectType.getDescribe();</pre><p><strong>Using the getSObjectType method of SObject instance</strong></p><p>Our above example is limited Account object. Let’s say we want our code to be more dynamic so that it returns an instance of DescribeSObjectResult for any SObject. We can use the following snippet:</p><pre>public DescribeSObjectResult describeSObject(String sObjectName) {<br>    Type t = Type.forName(sObjectName);<br>    SObject sObj = (SObject) t.newInstance();<br>    return sObj.getSObjectType().getDescribe();<br>}</pre><p>We can use getGlobalDescribe as well when we have sObjectName but that’s an overkill when we need an DescribeObjectResult instance for a particular SObject. For reference, let’s put that here as well</p><pre>String sObjectName = &#39;Account&#39;;<br>Map&lt;String, SObjectType&gt; objectMap = Schema.getGlobalDescribe();<br>SObjectType sObjType = objectMap.get(sObjectName);<br>DescribeSObjectResult objResult = sObjType.getDescribe();</pre><p><strong>Using the getSObjectType method on Id of the record</strong></p><p>There will be many scenarios where we won’t have the name of the SObject which we want to describe instead we will have Id a record that SObject with us. We can use the following approach to describe an SObject using the record Id:</p><pre>Id recordId = &#39;001000000000000&#39;;<br>DescribeSObjectResult objectResult = recordId.getSObjectType().getDescribe();</pre><p><strong>Conclusion</strong></p><p>There are multiple ways in which we can describe an SObject in Apex. We just need to find out what variables we have at hand and decide the approach we can use to describe an SObject based on that.</p><p>If you found this helpful, please don’t hold back your upvotes and you can follow me on <a href="https://medium.com/@jagmohan.singh.1">Medium</a> or <a href="https://twitter.com/JagmohanSingh">Twitter</a> for more tips and tricks related to Apex, Visualforce, Aura, Lightning Web Components and Salesforce platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a428dedd158" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sidestep the 2000 record limit in server-side pagination using Apex]]></title>
            <link>https://blog.cloudanswers.com/sidestep-the-2000-record-limit-in-server-side-pagination-using-apex-6573516d85bf?source=rss-366403654d57------2</link>
            <guid isPermaLink="false">https://medium.com/p/6573516d85bf</guid>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[pagination]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Jagmohan Singh]]></dc:creator>
            <pubDate>Wed, 02 Nov 2022 06:51:46 GMT</pubDate>
            <atom:updated>2022-11-02T06:51:46.699Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever tried implementing server-side pagination using Apex with Salesforce SOQL limit and offset clauses? If yes, then you might already know that Salesforce SOQL doesn’t support offset values more than 2000. That means you can’t load more than 2000 records even if they are spread across multiple pages.</p><p>In this article, I’ll show you an approach that doesn’t use the SOQL offset clause, thereby overcoming this limitation for large data sets.</p><h3>The Solution</h3><h4>Overview</h4><p>The key part of the solution is to pass the Id of the last or the first record from the current page based on whether we are trying to load the next or the previous page of records. Once we have the Id of the record for an already loaded page, page size and direction, we can use SOQL with filters on the Id field, limit and order by clauses to load the next set of records. Let’s see some code to understand this further:</p><pre><a href="http://twitter.com/RemoteAction">@RemoteAction</a><br>public static Map&lt;String, Object&gt; fetchRecords(String sObjectName, String lastKnownId, Integer pageSize, Integer direction) {</pre><pre>…</pre><pre>}</pre><p>In the above method, we are accepting four parameters:</p><ol><li>sObjectName: Used to specify the name of the object whose records we want to load</li><li>lastKnownId: This parameter can have different values depending upon which page and in what direction we are trying to load the records. For e.g. when loading the first page, this parameter will be null or an empty string with direction = 1; For loading the last page, this parameter will be null or an empty string with direction = -1; For loading the next page for the current page, this parameter will be the Id of the last record on the current page with direction = 1; For loading the previous page for the current page, this parameter will be the Id of the first record on the current page with direction = -1</li><li>pageSize: Used to specify the number of records to load per page</li><li>direction: Used to specify whether to load the next or the previous page</li></ol><h4>Details</h4><p><strong>Get the total numbers of records</strong></p><p>First of all, we find the total number of records for the specified object in the system. We can do that using the following method:</p><pre>public static Integer getTotalCount(String sObjectName) {<br>    Integer totalCount = 0;<br>    String query = &#39;select count(Id) totalCount from &#39; + sObjectName;<br>    List&lt;AggregateResult&gt; res = (List&lt;AggregateResult&gt;) Database.query(query);<br>    if (!res.isEmpty()) {<br>        totalCount = (Integer) res.get(0).get(&#39;totalCount&#39;);<br>    }<br>    return totalCount;<br>}</pre><p><strong>Calculate the total pages based on the total records and the page size</strong></p><p>Next, we calculate the total number of pages based on the total number of records and the specified page size. We can use the following formula to calculate that:</p><pre>Integer totalPages = (Integer) Math.ceil((Decimal) totalRecords / pageSize);</pre><p>The <strong>key thing</strong> to note here is the usage of Math.ceil method to round the argument to the nearest Decimal which is not less than the argument.</p><p><strong>Special Case: When starting from the last page</strong></p><p>If the user wants to navigate to the last page of records, we support this use case by passing lastKnownId = null and direction = -1. We calculate the number of records on the last page based on the page size passed from client-side and return only that many records in the response.</p><pre>public static Integer getLastPageRecordCount(Integer totalRecords, Integer pageSize) {<br>    Integer totalPages = (Integer) Math.ceil((Decimal) totalRecords / pageSize);<br>    Integer recordCount = totalRecords - ((totalPages - 1) * pageSize);<br>    return recordCount;<br>}</pre><p><strong>Load records</strong></p><p>Next, we build a SOQL query to fetch the records from the Salesforce database. We are using Schema describe methods to find all the fields accessible to the logged in user to build a list of fields. Then they are embedded in the select clause and specify the object name in the from clause of the SOQL query.</p><p>Now, we need to understand how the direction flag is used with lastKnownId. If the lastKnownId value is not blank, then based on the direction flag we will either load the next or previous set of records by using the greater or less than operators.</p><p>Another key thing to note is that we are querying one extra record per page. This will be used to deduce values for two flags; i.e. hasNext and hasPrevious and set them in the response. This will help us identity whether current page has a next or a previous page.</p><p>Lastly, we are ordering records in ascending or descending order based on the direction the user is trying to navigate. For e.g. when the user is navigating from the last page to its previous page, we pass direction = -1. When direction = -1, we order the records in descending order and limit the number of records to page size + 1. This gives the user the ability to paginate forward and backward in the pages.</p><pre>public static List&lt;SObject&gt; queryRecords(String sObjectName, String lastKnownId, Integer maxResults, Integer direction) {<br>    List&lt;String&gt; fields = describeSObjectFields(sObjectName);<br>    String query = &#39;select &#39; + String.join(fields, &#39;,&#39;);<br>    query += &#39; from &#39; + sObjectName;<br>    if (String.isNotBlank(lastKnownId)) {<br>        query += &#39; where Id &#39; + (direction == 1 ? &#39;&gt;&#39; : &#39;&lt;&#39;) + &#39; \&#39;&#39; + lastKnownId + &#39;\&#39; &#39;;<br>    }<br>    if (maxResults != null) {<br>        // query one extra record<br>        maxResults =  maxResults + 1;<br>        query += &#39; order by Id &#39; + (direction == 1 ? &#39;asc&#39; : &#39;desc&#39;) + &#39; limit :maxResults&#39;;<br>    }<br>    return Database.query(query);<br>}</pre><p><strong>Deduce the page state</strong></p><p>Once we have queried the records for the next or the previous page, we set the hasNext, hasPrevious, firstId, lastId properties in the response based on the number of records loaded on the page using the <strong>getPageState</strong> method in <strong>SObjectQueryService</strong> class. The idea behind setting the firstId and lastId properties in the response is to make the client side implementation easier. For e.g. if we use any kind of sorting mechanism on the client side, we might lose track of the original order of the records. These properties help easy access to those Ids and navigation between pages.</p><p><strong>Sort the records</strong></p><p>One last thing to note is that when the direction flag = -1, we are sorting the records before setting them into the response. The idea is to sort the records by Id in ascending order since we are retrieving the records sorted in descending order when navigating backwards.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15c1ba316665cf0bfc3900740d7e5fa8/href">https://medium.com/media/15c1ba316665cf0bfc3900740d7e5fa8/href</a></iframe><p>If you need help with Salesforce or have something little more complex that might require some advanced developer knowledge, you can contact us at <a href="/service/mailto:help@cloudanswers.com">help@cloudanswers.com</a> or chat with us on <a href="https://cloudanswers.com/?utm_source=Medium&amp;utm_medium=article&amp;utm_term=Server_side_pagination_using_Apex&amp;utm_content=CloudAnswers_website">https://cloudanswers.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6573516d85bf" width="1" height="1" alt=""><hr><p><a href="https://blog.cloudanswers.com/sidestep-the-2000-record-limit-in-server-side-pagination-using-apex-6573516d85bf">Sidestep the 2000 record limit in server-side pagination using Apex</a> was originally published in <a href="https://blog.cloudanswers.com/">CloudAnswers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System.ListException: Row with null Id at index]]></title>
            <link>https://medium.com/@jagmohan.singh.1/system-listexception-row-with-null-id-at-index-62a5084f838a?source=rss-366403654d57------2</link>
            <guid isPermaLink="false">https://medium.com/p/62a5084f838a</guid>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[apex]]></category>
            <category><![CDATA[exception]]></category>
            <dc:creator><![CDATA[Jagmohan Singh]]></dc:creator>
            <pubDate>Tue, 12 Jul 2022 17:38:31 GMT</pubDate>
            <atom:updated>2022-09-19T02:20:01.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bbc1VP4DPE0U5gpFCgVdCw.jpeg" /><figcaption>This photo by <a href="https://unsplash.com/@mostafa_meraji?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">mostafa meraji</a> on <a href="https://unsplash.com/s/photos/exception?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a> depicts a developer does while debugging.</figcaption></figure><p>Are you running into the above error and not able to figure the root cause? Look no further and read this article to understand and fix the issue in your code.</p><p>Here is a code snippet which results in the above exception:</p><pre>List&lt;Account&gt; accs = new List&lt;Account&gt;();<br>accs.add(new Account(Name=&#39;Test Account&#39;));<br>// next line results in above exception<br>Map&lt;Id, Account&gt; accsMap = new Map&lt;Id, Account&gt;(accs);</pre><p>Let’s understand this snippet. On the first line we have initialized a List of Account records. On the next line we added a new Account record to the list.</p><p><em>Note: The Account record has no Id field set.</em></p><p>On the last line, we are trying to initialize a Map with the list of accounts which we created earlier. This line results in above error because the Account record’s Id = null.</p><p>This error can creep into the code without you noticing it and you need to be careful while building Maps from Lists:</p><p>Here is an example which can result in the above error if any of the CustomObject__c record has LookupField__c = null.</p><pre>Map&lt;Id, AggregateResult&gt; result = Map&lt;Id, AggregateResult&gt;([select LookupField__c, count(Id) from CustomObject__c group by LookupField__c])</pre><p>To overcome the issue, we need to filter out the aggregation for null LookupField__c by using a filter in the where clause</p><pre>Map&lt;Id, AggregateResult&gt; result = Map&lt;Id, AggregateResult&gt;([select LookupField__c, count(Id) from CustomObject__c where LookupField__c != null group by LookupField__c])</pre><p>Thanks for reading. Hope this article helps you avoid the above error and save hours of debugging production code.</p><p>You can follow me on <a href="https://medium.com/@jagmohan.singh.1">Medium</a> or <a href="https://twitter.com/JagmohanSingh">Twitter</a> more tips related to Apex, Visualforce, Aura, Lightning Web Components and Salesforce platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62a5084f838a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Schedule an Apex Batch Job to run every X Minutes]]></title>
            <link>https://medium.com/@jagmohan.singh.1/schedule-an-apex-batch-job-to-run-every-x-minutes-d49fff74e71?source=rss-366403654d57------2</link>
            <guid isPermaLink="false">https://medium.com/p/d49fff74e71</guid>
            <category><![CDATA[batch]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[apex]]></category>
            <dc:creator><![CDATA[Jagmohan Singh]]></dc:creator>
            <pubDate>Sat, 09 Jul 2022 15:32:40 GMT</pubDate>
            <atom:updated>2022-07-09T15:32:40.817Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X_12RuZwnBGB9DjxS9w8yg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@goumbik?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Lukas Blazek</a> on <a href="https://unsplash.com/s/photos/schedule?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h4>Background</h4><p>Apex programming language provides classes and interfaces which can be used to run long running processes in the background on Salesforce platform. You can implement <a href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_database_batchable.htm">Database.Batchable</a> interface in your class which you want to run as a batch job.</p><p>If you want to run the batch job at a specific time in future, you would need another class which can be scheduled and starts the batch job. You can implement <a href="https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_system_schedulable.htm">System.Schedulable</a> interface in your Apex class to run it at specific times using the System.schedule method. This method accepts three params:</p><ol><li>Job name: This is the name of job</li><li>Schedule expression: This tells Salesforce when to run the job</li><li>Schedulable object: Instance of an Schedulable class to execute</li></ol><h4>Scenario</h4><p>Often times you might come across a scenario where you need to run a batch job every X minutes.</p><h4>Solution</h4><p>The schedule expression doesn’t support accepting multiple values for the Minutes part. However, it can be easily accomplished by submitting multiple schedule jobs to run with different schedule expressions having different Minutes values.</p><p>Let’s try to understand this with the help of an example. Suppose you want to run the batch job every 15 minutes i.e. 4 times an hour. You would need to submit 4 different scheduled jobs with following schedule expressions:</p><ol><li>0 0 * * * ?</li><li>0 15 * * * ?</li><li>0 30 * * * ?</li><li>0 45 * * * ?</li></ol><pre>SchedulableClassName obj = new SchedulableClassName();<br>String exp = &#39;0 0 * * * ?&#39;;<br>System.schedule(&#39;ScheduledJob1&#39;, exp, obj);<br>exp = &#39;0 15 * * * ?&#39;;<br>System.schedule(&#39;ScheduledJob2&#39;, exp, obj);<br>exp = &#39;0 30 * * * ?&#39;;<br>System.schedule(&#39;ScheduledJob3&#39;, exp, obj);<br>exp = &#39;0 45 * * * ?&#39;;<br>System.schedule(&#39;ScheduledJob4&#39;, exp, obj);</pre><p>You can use the same logic to run job every 10, 20, 30 minutes, etc.</p><p>For more information on schedule expressions, you can refer <a href="https://developer.salesforce.com/docs/atlas.en-us.238.0.apexcode.meta/apexcode/apex_scheduler.htm">Salesforce docs</a> or leave your comment if you have any questions. I will try my best to answer.</p><p>You can me on <a href="https://medium.com/@jagmohan.singh.1">Medium</a> or <a href="https://twitter.com/JagmohanSingh">Twitter</a> for more content related Salesforce platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d49fff74e71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Save DOM Element As Image Attachment In Salesforce]]></title>
            <link>https://blog.cloudanswers.com/save-dom-element-as-image-attachment-in-salesforce-f257f6cc678e?source=rss-366403654d57------2</link>
            <guid isPermaLink="false">https://medium.com/p/f257f6cc678e</guid>
            <category><![CDATA[salesforce-tools]]></category>
            <category><![CDATA[salesforce-productivity]]></category>
            <category><![CDATA[dom-elements]]></category>
            <category><![CDATA[conga-composer]]></category>
            <category><![CDATA[salesforce]]></category>
            <dc:creator><![CDATA[Jagmohan Singh]]></dc:creator>
            <pubDate>Thu, 08 Apr 2021 18:06:54 GMT</pubDate>
            <atom:updated>2021-04-08T18:06:54.578Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0aztN2M9L8uby0LvIXldsQ.png" /></figure><p>Did you ever have to capture a screenshot of a widget that displays some financial numbers in tabular format and then email those to a customer? Or maybe copy and paste the snapshot of financial numbers in a proposal document? If yes, in this article, we will see how to automate the process of capturing the snapshot and save it to Salesforce record for later use.</p><p>We will be using a <a href="https://www.npmjs.com/package/dom-to-image">dom-to-image</a> Javascript library that can turn arbitrary DOM nodes into a vector (SVG) or raster (PNG or JPEG) image. I have uploaded that library as a Static Resource in my dev org. It would be best if you did the same before trying out the code I have shared below.</p><p>The key steps and gotchas are explained in the following steps are:</p><ol><li>Capture the DOM element: This part is pretty straightforward. We can capture the DOM element using the standard document.getElementById() Javascript method.</li><li>Convert DOM element to Image: We have added a <strong>dom-to-image</strong> Javascript library for this step. This library has methods to convert the DOM node into a vector (SVG) or raster (PNG or JPEG) image. I’ve usedtoPng() the way it returns a promise and provides results in promise callback. This method returns the image in <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs">Data URIs</a> format. We need to extract (dataUrl.split(,)[1]) the data from Data URI before saving it as an Attachment body.</li><li>Save it as Attachment in Salesforce: I’m using Javascript remoting to send the data to the Apex controller. Since the <strong>dom-to-image </strong>library returns base64 encoded image data, we need to decode that before saving it in the Attachment record.</li></ol><p>The scenario which I came across was to pull data from a Matrix report into a Conga document. Since <a href="https://documentation.conga.com/cpsfwin20cg/gathering-data-for-composer/using-salesforce-reports-with-conga-composer/use-salesforce-reports-with-conga-composer">Conga Composer only supports the Tabular reports</a>, I decided to go with a custom solution to <a href="https://medium.com/cloudanswers/run-salesforce-reports-in-apex-1acd5b320853">run the report and export report data</a>. Then, I used a Visualforce component to render the data in the same format as that of a Salesforce Matrix report.</p><p>Once the report data is rendered in a Visualforce component, capture the DOM element, convert it into a PNG and save that as an Attachment on the Salesforce record as shown in the below snippet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c27131c60d8964a81bf87459e818c00f/href">https://medium.com/media/c27131c60d8964a81bf87459e818c00f/href</a></iframe><p>The saved attachment looks like as below for our use case:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*wIckStFWDuRT6Ndgzi1A5g.png" /><figcaption>Image from DOM</figcaption></figure><p>If you need help with Salesforce or have something a little more complex, that might require some advanced developer knowledge? We can help. Contact us at <a href="/service/mailto:help@cloudanswers.com">help@cloudanswers.com</a> or chat with us on<a href="https://cloudanswers.com/?utm_source=Medium&amp;utm_medium=article&amp;utm_term=Save_DOM%20Element_As_Image_Attachment_In_Salesforce&amp;utm_content=CloudAnswers_website"> www.cloudanswers.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f257f6cc678e" width="1" height="1" alt=""><hr><p><a href="https://blog.cloudanswers.com/save-dom-element-as-image-attachment-in-salesforce-f257f6cc678e">Save DOM Element As Image Attachment In Salesforce</a> was originally published in <a href="https://blog.cloudanswers.com/">CloudAnswers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Embed Image In Conga Document Using Salesforce ID]]></title>
            <link>https://blog.cloudanswers.com/embed-image-in-conga-document-using-salesforce-id-e8805b5746a8?source=rss-366403654d57------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8805b5746a8</guid>
            <category><![CDATA[salesforce-tools]]></category>
            <category><![CDATA[salesforce]]></category>
            <category><![CDATA[salesforce-lightning]]></category>
            <category><![CDATA[salesforce-development]]></category>
            <category><![CDATA[conga]]></category>
            <dc:creator><![CDATA[Jagmohan Singh]]></dc:creator>
            <pubDate>Fri, 26 Feb 2021 05:12:12 GMT</pubDate>
            <atom:updated>2021-02-26T05:12:12.459Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iBitdlH3UsVyhE_7bDPwiw.png" /></figure><p>Have you come across a scenario where you were required to dynamically pull the customer logo from Salesforce Documents or Attachments while creating a proposal, invoice, etc for a customer? This article explains how to do that.</p><p>I’m going to demonstrate how we can embed an image uploaded as an Attachment or Salesforce Document into a Conga document. As per the <a href="https://documentation.conga.com/cpsfwin20cg/creating-composer-templates/word-templates/advanced-word-templates/merge-images-with-salesforce-id-in-word">official Conga docs</a>, this approach works with images uploaded as Salesforce Documents or Attachments to a record.</p><p>For this article, let’s suppose we want to create a proposal for a customer from a Salesforce Quote. And, we want to dynamically pull the customer logo from the related Account record and embed it into the generated Conga document.</p><p>Now, let’s go through each step one by one.</p><h4>Create A Conga Query</h4><p>The first step is to create a Conga Query to fetch the Attachment record. Here is the Conga Query which I have set up for this example:</p><pre>select Id from Attachment where Description = ‘Logo’ and ParentId IN (select AccountId from Quote where Id = ‘{pv0}’) order by CreatedDate desc limit 1</pre><p>The above query will fetch the most recent Attachment record related to the Account related to the Quote record. And, it has another condition to filter the records by Description field to make sure it pulls the customer logo. The record, Quote in our case, from which we invoke Conga Composer, will replace <strong>‘{pv0}’ </strong>with the Id of that record. You can change the <strong>where clause </strong>as per your need to fetch the correct record. We just need the Id of the Attachment record, so just query that field.</p><p><em>Note: </em>If you copy and paste the above query, make sure your Attachment record’s Description is set to <strong>Logo.</strong></p><h4>Create Proposal Button on Quote Object</h4><p>In this step, we are going to create a button on the Quote object and add it to the page layout. I have set up the following button for this example and added it to the appropriate page layout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8AhXHs8h03oCWlwVDpMGQ.png" /><figcaption>Create Proposal (Lightning Version)</figcaption></figure><p>URL for Salesforce Lightning button</p><pre>/apex/APXTConga4__Conga_Composer?serverUrl={!API.Partner_Server_URL_290}&amp;id={!Quote.Id}&amp;QueryId=[Attachment]a1b63000005d8MHAAY&amp;WordStripIfs=1&amp;SC0=1&amp;SC1=SalesforceFile&amp;OFN={!Quote.Name}</pre><p>The above button works for the Lightning Experience. For Salesforce Classic you would need to set up a different button which looks like as shown below and makes sure this button shows up for users in Salesforce Classic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qv-i25qrjkIVkF9iSC6XjA.png" /><figcaption>Create Proposal (Classic Version)</figcaption></figure><p>URL for Salesforce Classic button</p><pre>https://composer.congamerge.com?sessionId={!API.Session_ID}&amp;serverUrl={!API.Partner_Server_URL_290}&amp;id={!Quote.Id}&amp;QueryId=[Attachment]a1b63000005d8MHAAY&amp;WordStripIfs=1&amp;SC0=1&amp;SC1=SalesforceFile&amp;OFN={!Quote.Name}</pre><h4>Let’s Test What We Have So Far</h4><p>Before we proceed further, let’s make sure we can retrieve the attachment record in the Conga Composer with the Conga Query which we have setup. For that follow the following steps:</p><ol><li>Create or go to an existing Account record</li><li>Upload a customer logo as an attachment to Account (<em>Tip: You may need to switch to Salesforce Classic to upload the file as an Attachment)</em></li><li>On the Quote detail page, click on the Create Proposal button. This will open Conga Composer</li><li>On Conga Composer, click Template Builder under Tools &amp; Settings</li></ol><p>If everything is set up correctly, we should see the query result for the <strong>Attachment</strong> query as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3nAt-SzFkYfQdoc77_LEA.png" /><figcaption>Template Builder</figcaption></figure><p>If you were able to see the Attachment record in Template Builder, as shown above, let’s go ahead with the next steps. Otherwise, revisit the previous steps and make sure everything is set up correctly.</p><h4>Add IMAGE Tag To Conga Template</h4><p>In this step, we are going to add the Conga IMAGE tag to a Conga Template and see the result in the generated document. Here is a <a href="https://drive.google.com/file/d/1Kbq9UPc9DUreReFm4upLU0STeU97rBZe/view?usp=sharing">sample template</a> that I have created for this article.</p><p><strong>Note:</strong> You can try with the above template or copy and paste the tags from my template into your template.</p><p>Now, let’s test the above template in Conga Composer.</p><ul><li>On Conga Composer, choose the Local Template tab and select the Conga Template as shown below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JPwAvH78eKQlOTLytNyQFA.png" /><figcaption>Select Template</figcaption></figure><ul><li>After selecting the file, click on the Preview button.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hAsYKvg5-qRY3wmjwyOzQA.png" /><figcaption>Preview Template</figcaption></figure><p>Here is how the generated doc looks for me.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tJ_sm9d-XEo0CbslHrXhdw.png" /><figcaption>Generated doc with embedded customer logo from Account.</figcaption></figure><h4>Conclusion</h4><p>We can use the Conga IMAGE tag to embed images uploaded as attachments to a Salesforce record. We can extend this example to different real-world use cases and the possibilities are endless.</p><p>If you need help with Salesforce or have something a little more complex that might require advanced developer knowledge? We can help. Contact us at <a href="/service/mailto:help@cloudanswers.com">help@cloudanswers.com</a> or chat with us on <a href="http://www.cloudanswers.com/">www.cloudanswers.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8805b5746a8" width="1" height="1" alt=""><hr><p><a href="https://blog.cloudanswers.com/embed-image-in-conga-document-using-salesforce-id-e8805b5746a8">Embed Image In Conga Document Using Salesforce ID</a> was originally published in <a href="https://blog.cloudanswers.com/">CloudAnswers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>