<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>js &#8211; Hamza Siddiqui</title>
	<atom:link href="https://www.mhamzas.com/blog/tag/js/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mhamzas.com</link>
	<description>4x Salesforce MVP &#124; 26x Certified &#124; Salesforce App &#38; System Architect</description>
	<lastBuildDate>Fri, 10 Mar 2023 07:55:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">233526040</site>	<item>
		<title>Salesforce Web to lead and Web to Case using Javascript [CORS Proof !]</title>
		<link>https://www.mhamzas.com/blog/2023/03/10/salesforce-web-to-lead-and-web-to-case-using-javascript-cors-proof-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=salesforce-web-to-lead-and-web-to-case-using-javascript-cors-proof-2</link>
					<comments>https://www.mhamzas.com/blog/2023/03/10/salesforce-web-to-lead-and-web-to-case-using-javascript-cors-proof-2/#respond</comments>
		
		<dc:creator><![CDATA[hamza]]></dc:creator>
		<pubDate>Fri, 10 Mar 2023 07:55:08 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[web2case]]></category>
		<category><![CDATA[web2lead]]></category>
		<guid isPermaLink="false">https://www.mhamzas.com/?p=3513</guid>

					<description><![CDATA[Ever faced a CORS issue while trying to embed Web to lead or Web to Case in your website? CORS Cross-Origin Resource Sharing (CORS) is an HTTP-header-based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than <br /><a href="https://www.mhamzas.com/blog/2023/03/10/salesforce-web-to-lead-and-web-to-case-using-javascript-cors-proof-2/" class="more-link btn btn-primary">Read More</a>]]></description>
										<content:encoded><![CDATA[
<p>Ever faced a CORS issue while trying to embed Web to lead or Web to Case in your website?</p>



<h2 class="wp-block-heading">CORS</h2>



<p>Cross-Origin Resource Sharing (CORS) is an HTTP-header-based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources.<br>Cross-Origin Resource Sharing (CORS) errors <strong>occur when a server doesn&#8217;t return the HTTP headers required by the CORS standard</strong>. To resolve a CORS error from an API Gateway REST API or HTTP API, you must reconfigure the API to meet the CORS standard.</p>



<figure class="wp-block-image size-full"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="640" height="182" src="https://i0.wp.com/www.mhamzas.com/wp-content/uploads/2023/03/image.png?resize=640%2C182&#038;ssl=1" alt="" class="wp-image-3515" srcset="https://i0.wp.com/www.mhamzas.com/wp-content/uploads/2023/03/image.png?w=790&amp;ssl=1 790w, https://i0.wp.com/www.mhamzas.com/wp-content/uploads/2023/03/image.png?resize=300%2C85&amp;ssl=1 300w, https://i0.wp.com/www.mhamzas.com/wp-content/uploads/2023/03/image.png?resize=768%2C219&amp;ssl=1 768w" sizes="(max-width: 640px) 100vw, 640px" /></figure>



<h2 class="wp-block-heading">Solution</h2>



<p>Here&#8217;s a workaround using the form in HTML and processing it through Javascript.</p>



<script src="https://gist.github.com/mhamzas/f2c445ce18bb71b5fce193eddd7ed007.js"></script>



<p>Happy Coding!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.mhamzas.com/blog/2023/03/10/salesforce-web-to-lead-and-web-to-case-using-javascript-cors-proof-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3513</post-id>	</item>
		<item>
		<title>LWC Best Practices &#038; Considerations</title>
		<link>https://www.mhamzas.com/blog/2021/05/23/lwc-best-practices-considerations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lwc-best-practices-considerations</link>
					<comments>https://www.mhamzas.com/blog/2021/05/23/lwc-best-practices-considerations/#respond</comments>
		
		<dc:creator><![CDATA[hamza]]></dc:creator>
		<pubDate>Sun, 23 May 2021 02:11:00 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[lwc]]></category>
		<guid isPermaLink="false">https://www.mhamzas.com/?p=3244</guid>

					<description><![CDATA[Hi again! This blog post is going to be a different one as I&#8217;ll keep updating this post with all the latest findings. In this blog post, I am going to share all the best practices and considerations regarding LWC for not <br /><a href="https://www.mhamzas.com/blog/2021/05/23/lwc-best-practices-considerations/" class="more-link btn btn-primary">Read More</a>]]></description>
										<content:encoded><![CDATA[
<p>Hi again! This blog post is going to be a different one as I&#8217;ll keep updating this post with all the latest findings.</p>



<p>In this blog post, I am going to share all the best practices and considerations regarding LWC for not just by the Salesforce but even with personal experience.</p>



<p>First, let&#8217;s start with <strong>FOR LOOP</strong>,</p>



<p><strong>1- FOR LOOP</strong></p>



<p>JS ES6 bring a different kind of FOR LOOPS (<a href="https://niksdeveloper.com/salesforce/loop-through-list-in-lwc-and-javascript/" target="_blank" rel="noreferrer noopener nofollow">click here</a> to have a look in details) but in LWC &#8211; make sure to use the one which doesn&#8217;t conflict with lwc architecture.</p>



<p>For example, if you&#8217;re going to use <strong>forEach</strong>,</p>



<pre class="wp-block-code"><code>this.lstAccounts.forEach(function(acc){
    console.log(acc.Name);
});</code></pre>



<p>You won&#8217;t be able to access THIS.VARIABLE inside this loop. Here is a demonstration, </p>



<pre class="wp-block-code"><code>this.lstAccounts.forEach(function(acc){
    console.log(acc.Name);
    console.log(this.someBooleanval); //THIS VALUE WILL BE NULL
});</code></pre>



<p>The reason is that such kind of loop also uses THIS. and looks for the value inside a loop where such variable is not assigned hence &#8211; NULL.</p>



<p>SO what should you do ? Use another kind of FOR LOOP &#8211; like:</p>



<pre class="wp-block-code"><code>for(let acc of this.lstAccounts){
    console.log(acc.Name);
   console.log(this.someBooleanval); //VALUE WILL BE ACCESSIBLE HERE
}</code></pre>



<p><strong>2- Dealing with Time field</strong></p>



<p>The number you are getting is in milliseconds &#8220;65700000&#8221;. We need to convert it to time format in js itself. I used the below method to do so.</p>



<pre class="wp-block-code"><code>// Convert milliseconds into 'h:mm a' time format
    msToTime(s){
        let ms = s % 1000;
        s = (s - ms) / 1000;
        let secs = s % 60;
        s = (s - secs) / 60;
        let mins = s % 60;
        let hrs = (s - mins) / 60;
        hrs = hrs &lt; 10 ? '0' + hrs : hrs;
        mins = mins &lt; 10 ? '0' + mins : mins;
        console.log(hrs + '  ' + mins);
        return hrs+':' + mins + ':00.000Z';
    }</code></pre>



<p><strong>3-</strong> <strong>setInterval Binding</strong></p>



<p id="c2ba">setInterval runs on different browser subthread thingy… That is it doesn’t maintain the context of what happens after.</p>



<p id="015f">Take this code for eg.</p>



<pre class="wp-block-preformatted">var count = 0;<br>var intervalID = setInterval(function (){<br>  this.count++;<br>  console.log(this.count);     // prints number from 0 to percentage<br>  if (this.count === this.percentage) {<br>    clearInterval(intervalID);<br>  }<br>},10)<br>console.log(this.count);       // prints 0 </pre>



<p id="995a">The second console prints ‘0&#8242;, which explains the fact that context is not maintained. To make that happen we bind the context to each anonymous function call that is made.</p>



<p id="bea6">Just use</p>



<pre class="wp-block-preformatted">.bind(this) // 'this' is the context</pre>



<p id="46e9">So the JS becomes,</p>



<pre class="wp-block-preformatted">import { LightningElement, track } from 'lwc';<br>export default class App extends LightningElement {<br>  @track count = 0;<br>  @track percentage = 99;<br>  <br>  connectedCallback() {<br>    var intervalID = setInterval(function (){<br>      this.count++;<br>      if (this.count === this.percentage) {<br>        clearInterval(intervalID);<br>      }<br>    }.bind(this),10);<br>  }<br>}</pre>



<p>I hope this will help you at some point &#8211; I&#8217;ll keep updating this post with latest updates.</p>



<p>Happy Coding!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.mhamzas.com/blog/2021/05/23/lwc-best-practices-considerations/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3244</post-id>	</item>
		<item>
		<title>setTimeout in Lightning Component [AURA]</title>
		<link>https://www.mhamzas.com/blog/2020/04/15/settimeout-in-lightning-component-aura/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=settimeout-in-lightning-component-aura</link>
					<comments>https://www.mhamzas.com/blog/2020/04/15/settimeout-in-lightning-component-aura/#respond</comments>
		
		<dc:creator><![CDATA[hamza]]></dc:creator>
		<pubDate>Tue, 14 Apr 2020 19:40:12 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[aura]]></category>
		<category><![CDATA[js]]></category>
		<guid isPermaLink="false">https://www.mhamzas.com/?p=3086</guid>

					<description><![CDATA[I found it very important as many places, JS functions can save your a**. I mean LIFE. But specially setTimeout function when you need to perform some function after specific time. Here is an example to use JS setTimeout function in AURA <br /><a href="https://www.mhamzas.com/blog/2020/04/15/settimeout-in-lightning-component-aura/" class="more-link btn btn-primary">Read More</a>]]></description>
										<content:encoded><![CDATA[
<p>I found it very important as many places, JS functions can save your a**. I mean LIFE. But specially setTimeout function when you need to perform some function after specific time.</p>



<p>Here is an example to use JS setTimeout function in AURA Component,</p>



<p>1. If set timeout modifies any attributes, use $A.callback-</p>



<pre class="wp-block-code"><code>window.setTimeout(
     $A.getCallback(function() {
          helper.hideSpinner(component, helper)
     }), 500
);</code></pre>



<p>2. As per <a href="https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout" target="_blank" rel="noreferrer noopener">setTimeout documentation</a>, use any one of the following if calling function doesn&#8217;t modifies any attributes:</p>



<pre class="wp-block-code"><code>window.setTimeout(function(){ helper.hideSpinner(component, helper)}, 500);
// or
window.setTimeout(helper.hideSpinner, 500, component, helper);</code></pre>



<p>Sources, </p>



<p><a href="https://github.com/edelrabe/Salesforce-Recipes/wiki/setTimeout-in-Lightning-Component">https://github.com/edelrabe/Salesforce-Recipes/wiki/setTimeout-in-Lightning-Component</a><br><a href="https://salesforce.stackexchange.com/questions/206017/lightning-component-error-for-settimeout-bind-must-be-called-on-a-function/206018">https://salesforce.stackexchange.com/questions/206017/lightning-component-error-for-settimeout-bind-must-be-called-on-a-function/206018</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.mhamzas.com/blog/2020/04/15/settimeout-in-lightning-component-aura/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3086</post-id>	</item>
	</channel>
</rss>
