<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Crypto Geek</title>
    <description>The latest articles on Forem by Crypto Geek (@cryptogeekus).</description>
    <link>https://forem.com/cryptogeekus</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F869572%2F776167f9-ca44-4b9c-8b08-7ebe473c6f9c.jpg</url>
      <title>Forem: Crypto Geek</title>
      <link>https://forem.com/cryptogeekus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/cryptogeekus"/>
    <language>en</language>
    <item>
      <title>Lazy Loading Collections in JavaScript</title>
      <dc:creator>Crypto Geek</dc:creator>
      <pubDate>Thu, 12 Jan 2023 15:54:55 +0000</pubDate>
      <link>https://forem.com/cryptogeekus/lazy-loading-collections-in-javascript-1ee1</link>
      <guid>https://forem.com/cryptogeekus/lazy-loading-collections-in-javascript-1ee1</guid>
      <description>&lt;p&gt;Lazy loading is a design pattern where a collection of items is only loaded when it is needed, rather than all at once. This can be useful for improving the performance and efficiency of a JavaScript application, particularly when working with large collections of data. &lt;/p&gt;

&lt;p&gt;There are several libraries and techniques available for implementing lazy loading in JavaScript, such as the lazy.js library and the IntersectionObserver API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lazy Loading Collections Example
&lt;/h2&gt;

&lt;p&gt;Here is an example of how to implement lazy loading using the lazy.js library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const lazy = require('lazy.js');
const largeCollection = lazy.range(1, 1000000);
const lazyLoadedCollection = largeCollection.lazy();
console.log(lazyLoadedCollection.take(10).toArray()); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the largeCollection variable contains a range of 1 million numbers, but it is wrapped in the lazy() function provided by the lazy.js library, creating a lazy-loaded collection. The take(10) method is used to retrieve the first 10 elements of the collection, and the toArray() method is used to convert them into an array.&lt;/p&gt;

&lt;p&gt;Another example is using the IntersectionObserver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const images = document.querySelectorAll('img[data-src]');
const observer = new IntersectionObserver((entries) =&amp;gt; {
  entries.forEach((entry) =&amp;gt; {
    if (entry.isIntersecting) {
      const img = entry.target;
      img.src = img.dataset.src;
      observer.unobserve(img);
    }
  });
});
images.forEach((image) =&amp;gt; {
  observer.observe(image);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the querySelectorAll method is used to select all img elements with a data-src attribute. An IntersectionObserver is then created to watch for when each image comes into view. As soon as an image comes into view, the src attribute is set to the value of the data-src attribute, loading the image and unobserving it. &lt;/p&gt;

&lt;p&gt;You can also implement &lt;a href="https://javahubscript.com/lazy-load-collection-list-with-filters-in-Javascript/" rel="noopener noreferrer"&gt;lazy loading collections with filters&lt;/a&gt; in Javascript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pros of Lazy Loading
&lt;/h2&gt;

&lt;p&gt;There are several advantages to using lazy loading in JavaScript:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Improved performance&lt;/strong&gt;: Lazy loading allows you to only load the data that is currently needed, which can significantly improve the performance of your application, especially when working with large collections of data.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduced memory usage&lt;/strong&gt;: By only loading the data that is needed, lazy loading can also help to reduce the amount of memory used by your application, which can lead to better overall performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better user experience&lt;/strong&gt;: Lazy loading can also improve the user experience by reducing the amount of time it takes for the page to load, and by only loading the content that is currently visible to the user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduced network traffic&lt;/strong&gt;: If your application retrieves data from a remote server, lazy loading can also help to reduce the amount of network traffic and improve the responsiveness of the application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better code organization&lt;/strong&gt;: Lazy loading can also make your code more organized by loading data and components only when they are needed, which can make it easier to maintain and understand the code.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cons of Lazy Loading
&lt;/h2&gt;

&lt;p&gt;While lazy loading can offer many benefits, there are also some potential downsides to consider:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Increased complexity&lt;/strong&gt;: Implementing lazy loading can add complexity to your code, which can make it more difficult to understand and maintain. This can be especially true if you are using a third-party library or API to implement lazy loading, as it may require additional setup and configuration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Increased development time&lt;/strong&gt;: Implementing lazy loading can also take more time to develop, as you will need to ensure that your data is loaded correctly and at the right time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limited browser support&lt;/strong&gt;: Some of the JavaScript libraries or APIs used for implementing lazy loading may not be supported by all browsers, which can make it difficult to ensure that your application works correctly across all platforms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User confusion&lt;/strong&gt;: Lazy loading can cause confusion for some users, as the page may not appear to be fully loaded or may not have all the information they need at first glance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Additional server load&lt;/strong&gt;: Lazy loading can cause more requests to be sent to the server, as the data is loaded in chunks, which can increase the server load and cause some additional latency.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>Updating Record in Salesforce With Mulesoft</title>
      <dc:creator>Crypto Geek</dc:creator>
      <pubDate>Mon, 09 Jan 2023 05:09:35 +0000</pubDate>
      <link>https://forem.com/cryptogeekus/updating-record-in-salesforce-with-mulesoft-h0f</link>
      <guid>https://forem.com/cryptogeekus/updating-record-in-salesforce-with-mulesoft-h0f</guid>
      <description>&lt;p&gt;In this tutorial, we are going to build a simple &lt;a href="https://bigdataers.com/category/mulesoft"&gt;mulesoft&lt;/a&gt; api that updates an account record in salesforce.&lt;/p&gt;

&lt;p&gt;This article is written with an assumption that you have a basic knowledge of Mulesoft, Salesforce and also the required access to these applications.&lt;/p&gt;

&lt;p&gt;We will follow the below steps to create a Mulesoft API that updates record in salesforce.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a Mule API&lt;/li&gt;
&lt;li&gt;Configure salesforce connector&lt;/li&gt;
&lt;li&gt;Create Mule Flow&lt;/li&gt;
&lt;li&gt;Test the API&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create a Mule API
&lt;/h2&gt;

&lt;p&gt;The first step is to create a new mule project in the Anypoint Studio tool. Follow the below steps to create a new mule project.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download and install the Anypoint studio on your PC.&lt;/li&gt;
&lt;li&gt;Open the the studio&lt;/li&gt;
&lt;li&gt;On the toolbar, click File -&amp;gt; New -&amp;gt; Mule Project.&lt;/li&gt;
&lt;li&gt;Enter the project name as sfdc-update &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Configure Salesforce Connector
&lt;/h2&gt;

&lt;p&gt;Lets add the salesforce connector to this mule project. Open the pom.xml file and add the following dependency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
  &amp;lt;groupId&amp;gt;com.mulesoft.connectors&amp;lt;/groupId&amp;gt;
  &amp;lt;artifactId&amp;gt;mule-salesforce-connector&amp;lt;/artifactId&amp;gt;
  &amp;lt;version&amp;gt;10.13.0&amp;lt;/version&amp;gt;
  &amp;lt;classifier&amp;gt;mule-plugin&amp;lt;/classifier&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you save the pom file, Anypoint studio will connect to the maven/mule exchange and downloads the required jar files.&lt;/p&gt;

&lt;p&gt;Once the salesforce connector is added to your application, its time to create a connection to the salesforce.&lt;/p&gt;

&lt;p&gt;Next, open the sfdc-update.xml file and go to the configuration XML tab. Add the following code between the  xml tags.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;salesforce:sfdc-config name="Salesforce_Config" doc:name="Salesforce Config" doc:id="0e7bcc62-c0ba-4af1-8f3b-23fd83a2ee06" &amp;gt;
        &amp;lt;salesforce:basic-connection username="sfdcUser" password="sfdcPassword" securityToken="sfdcToken" url="sfdcURL" /&amp;gt;
    &amp;lt;/salesforce:sfdc-config&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here replace sfdcUser, sfdcPassword, sfdcToken and sfdcURL with your salesforce credentials.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Mule Flow
&lt;/h2&gt;

&lt;p&gt;Create a mule flow using the following components.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flow&lt;/li&gt;
&lt;li&gt;Http Listener&lt;/li&gt;
&lt;li&gt;Transform Message&lt;/li&gt;
&lt;li&gt;Salesforce update component&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The below code shows the complete mule flow for updating record in salesforce.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;

&amp;lt;mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:salesforce="http://www.mulesoft.org/schema/mule/salesforce"
    xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/salesforce http://www.mulesoft.org/schema/mule/salesforce/current/mule-salesforce.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd"&amp;gt;
    &amp;lt;salesforce:sfdc-config name="Salesforce_Config" doc:name="Salesforce Config" doc:id="0e7bcc62-c0ba-4af1-8f3b-23fd83a2ee06" &amp;gt;
        &amp;lt;salesforce:basic-connection username="sfdcUser" password="sfdcPassword" securityToken="sfdcToken" url="sfdcURL" /&amp;gt;
    &amp;lt;/salesforce:sfdc-config&amp;gt;
    &amp;lt;http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="59da75a4-21be-4dc2-88dc-33ef9b0f5bd4" &amp;gt;
        &amp;lt;http:listener-connection host="0.0.0.0" port="8081" /&amp;gt;
    &amp;lt;/http:listener-config&amp;gt;
    &amp;lt;flow name="sfdc-updateFlow" doc:id="c66b8839-0094-45d2-bf53-6842bf00a0c2" &amp;gt;
        &amp;lt;http:listener doc:name="Listener" doc:id="9f3abfa4-e288-4427-b7f7-0728886d8dec" config-ref="HTTP_Listener_config" path="/salesforce"/&amp;gt;
        &amp;lt;ee:transform doc:name="Transform Message" doc:id="359433a3-5998-47e6-9c6b-6d6355792300" &amp;gt;
            &amp;lt;ee:message &amp;gt;
                &amp;lt;ee:set-payload &amp;gt;&amp;lt;![CDATA[%dw 2.0
output application/java
---
[
    {
        "id" : payload.id,
        "name" : payload.name
    }
]]]&amp;gt;&amp;lt;/ee:set-payload&amp;gt;
            &amp;lt;/ee:message&amp;gt;
        &amp;lt;/ee:transform&amp;gt;
        &amp;lt;salesforce:update doc:name="Update" doc:id="109eb69f-46c4-4fcf-b6c7-81a07659e9b2" config-ref="Salesforce_Config" type="Account"/&amp;gt;
        &amp;lt;ee:transform doc:name="Transform Message" doc:id="64d5e74c-d78d-4d92-9d3f-70dcd1a74863" &amp;gt;
            &amp;lt;ee:message &amp;gt;
                &amp;lt;ee:set-payload &amp;gt;&amp;lt;![CDATA[%dw 2.0
output application/json
---
payload]]&amp;gt;&amp;lt;/ee:set-payload&amp;gt;
            &amp;lt;/ee:message&amp;gt;
        &amp;lt;/ee:transform&amp;gt;
    &amp;lt;/flow&amp;gt;

&amp;lt;/mule&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can read more about other salesforce DML operations &lt;a href="https://bigdataers.com/tech/mulesoft-salesforce-connector-with-examples/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the API
&lt;/h2&gt;

&lt;p&gt;It is time to test the API to whether it is working or not. Deploy the Mule API in the anypoint studio. The API by default runs on 8081 port. &lt;/p&gt;

&lt;p&gt;Run the below curl command to test this api&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -X POST \
  http://localhost:8081/salesforce \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 24367e0a-2dc4-ea67-aa9d-bab35f246053' \
  -d '{
    "id" : "001000000000ABC",
    "name" : "Dev To"
}'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>mulesofthackathon</category>
      <category>salesforce</category>
    </item>
  </channel>
</rss>
