<?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>Integration Patterns &#8211; Jitendra Zaa</title>
	<atom:link href="https://www.jitendrazaa.com/blog/tag/integration-patterns/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.jitendrazaa.com/blog</link>
	<description>AI, Salesforce, ServiceNow &#38; Enterprise Tech Guides</description>
	<lastBuildDate>Sat, 06 May 2023 13:36:25 +0000</lastBuildDate>
	<language>en</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">87744916</site><atom:link rel="search" type="application/opensearchdescription+xml" title="Search Jitendra Zaa" href="https://www.jitendrazaa.com/blog/wp-json/opensearch/1.1/document" />	<item>
		<title>Salesforce Integration with Nodejs based applications using Canvas</title>
		<link>https://www.jitendrazaa.com/blog/salesforce/salesforce-integration-with-nodejs-based-applications-using-canvas/</link>
					<comments>https://www.jitendrazaa.com/blog/salesforce/salesforce-integration-with-nodejs-based-applications-using-canvas/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Mon, 20 Jul 2020 06:29:06 +0000</pubDate>
				<category><![CDATA[Integration]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Integration Patterns]]></category>
		<category><![CDATA[NodeJs]]></category>
		<category><![CDATA[Video Tutorial]]></category>
		<guid isPermaLink="false">https://www.jitendrazaa.com/blog/?p=7147</guid>

					<description><![CDATA[How to use Canvas Signed Request Authentication with web based applications like Nodejs &#038; how to use Canvas LifeCycle Handler Class]]></description>
										<content:encoded><![CDATA[
<p class="justify">Salesforce provides many ways to integrate with external systems like SOAP, Rest, Bulk API, User Interface API and so on. One of useful way to integrate any existing web applications with Salesforce is using Canvas.</p>



<p class="justify">For sake of this post, I&#8217;m using Nodejs application and complete source code can be found <a href="https://github.com/JitendraZaa/CanvasDemo">here</a> , on my <a href="https://github.com/JitendraZaa/CanvasDemo">Github repository</a>. It can be deployed on Heroku easily, however I used my local computer to run canvas. That also proves point that integration is happening via Browser and therefore canvas application can be hosted on premise and <a href="https://en.wikipedia.org/wiki/DMZ_(computing)">not necessarily on DMZ layer</a>.</p>



<h3 class="wp-block-heading">Step 1 : Create Connected App in Salesforce</h3>



<p class="justify">Enable OAuth in Connected app and provide any Callback URL. Canvas app does not use callback URL however we DO NEED scope. </p>



<p class="justify">Next step would be enabling canvas app itself connected app along with locations where we would be using it. </p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="1024" height="753" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2020/07/Salesforce-Canvas-App-in-Nodejs.png?resize=1024%2C753&#038;ssl=1" alt="" class="wp-image-7149" srcset="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2020/07/Salesforce-Canvas-App-in-Nodejs.png?resize=1024%2C753&amp;ssl=1 1024w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2020/07/Salesforce-Canvas-App-in-Nodejs.png?resize=300%2C221&amp;ssl=1 300w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2020/07/Salesforce-Canvas-App-in-Nodejs.png?resize=768%2C565&amp;ssl=1 768w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2020/07/Salesforce-Canvas-App-in-Nodejs.png?resize=1536%2C1130&amp;ssl=1 1536w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2020/07/Salesforce-Canvas-App-in-Nodejs.png?resize=1200%2C882&amp;ssl=1 1200w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2020/07/Salesforce-Canvas-App-in-Nodejs.png?w=1678&amp;ssl=1 1678w" sizes="(max-width: 1000px) 100vw, 1000px" /></figure>



<span id="more-7147"></span>



<h3 class="wp-block-heading">Step 2 : Wrap Canvas Connected App in Visualforce</h3>



<p class="justify">In this post, we will host canavs app in Visualforce page and then add Visualforce page on Account page. LWC still odes not support Canvas app and I&#8217;m not huge fan of Aura , so VF fits the bill for quick demo.</p>



<p>Visualforce Source Code</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;apex:page standardController=&quot;Account&quot;&gt;
    &lt;apex:canvasApp applicationName=&quot;Localhost_Connected_App&quot; 
        height=&quot;2000px&quot; width=&quot;750px&quot;/&gt;
&lt;/apex:page&gt;
</pre></div>


<p class="justify">For more advance control &amp; granular capability, we can inject Lifecycle class in Canvas app, full documentation can be found in <a href="https://developer.salesforce.com/docs/atlas.en-us.platform_connect.meta/platform_connect/canvas_creating_a_new_canvaslifecyclehandler.htm">canvas developer guide here</a>. Below source code I&#8217;ve used in video demo</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
/**
 * Sample Apex class to show case Canvas Life Cycle class demo
 */
public with sharing class CanvasDemoAppLifeCycle 
    implements Canvas.CanvasLifecycleHandler {

        public Set&lt;Canvas.ContextTypeEnum&gt; excludeContextTypes(){
            Set&lt;Canvas.ContextTypeEnum&gt; excluded = new Set&lt;Canvas.ContextTypeEnum&gt;();
    
            // Code goes here to add items to excluded list
            // that should be excluded from Context data
    
            return excluded;
        }
    
        public void onRender(Canvas.RenderContext renderContext) {   
            // Get the Application and Environment context from the RenderContext
            Canvas.ApplicationContext app = renderContext.getApplicationContext();
            Canvas.EnvironmentContext env = renderContext.getEnvironmentContext();

            if (false){ 
                throw new Canvas.CanvasRenderException(&#039;This is sample error message&#039;);
            } 

            Set&lt;String&gt; fields = new Set&lt;String&gt;{&#039;*&#039;,&#039;Name&#039;};
            //env.addEntityFields(fields);  
        }
    }
</pre></div>


<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Salesforce Integration using Canvas for Nodejs based applications" width="500" height="281" src="https://www.youtube.com/embed/FhMzTt8IShw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/salesforce/salesforce-integration-with-nodejs-based-applications-using-canvas/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">7147</post-id>	</item>
		<item>
		<title>Salesforce to Salesforce integration using Canvas</title>
		<link>https://www.jitendrazaa.com/blog/salesforce/salesforce-to-salesforce-integration-using-canvas/</link>
					<comments>https://www.jitendrazaa.com/blog/salesforce/salesforce-to-salesforce-integration-using-canvas/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Mon, 14 Sep 2015 03:05:40 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Integration Patterns]]></category>
		<category><![CDATA[SSO]]></category>
		<guid isPermaLink="false">http://www.jitendrazaa.com/blog/?p=4807</guid>

					<description><![CDATA[After writing this article Salesforce has enabled CSP (Content Security Policy) which restricts adding Salesforce in iFrame. We can add MyDomain URL as CSP whitelisting and it works only if user already logged into other Salesforce instance. However, if user is not logged into other instance , internally OAuth navigates through login.salesforce.com which is too [&#8230;]]]></description>
										<content:encoded><![CDATA[
<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="has-tertiary-background-color has-background">After writing this article Salesforce has enabled CSP (Content Security Policy) which restricts adding Salesforce in iFrame. We can add MyDomain URL as CSP whitelisting and it works only if user already logged into other Salesforce instance. However, if user is not logged into other instance , internally OAuth navigates through login.salesforce.com which is too restrictive and canvas application fails to load. </p>
</blockquote>


<p style="text-align: justify;">In this post we will discuss how Canvas can be used to integrate Salesforce with Salesforce. On my blog we have seen many articles and possibilities to integrate Salesforce with another Salesforce instance like <a href="https://www.jitendrazaa.com/blog/salesforce/salesforce-to-salesforce-integration-using-named-credentials-in-just-5-lines-of-code/">this</a> and <a href="https://www.jitendrazaa.com/blog/salesforce/getting-record-from-one-salesforce-organization-to-other/">this </a>post.</p>
<p><strong>Whats is force.com Canvas</strong></p>
<p style="text-align: justify;">Force.com Canvas SDK from Salesforce allows developers to connect existing legacy system or any web based application with Salesforce using JavaScript and REST API. Canvas applications can be displayed in Chatter, Salesforce Mobile Cards or Visualforce page.</p>
<p><strong>Why we are accessing another Salesforce instance as Canvas app</strong></p>
<p style="text-align: justify;">To get hands on with Canvas, most of article are around creating Heroku applications. I understand there are few developers who are not comfortable with Heroku. So to keep learning curve less, lets use Visualforce page to be exposed as Canvas application after all Visualforce is very advance MVC framework in itself.<span id="more-4807"></span></p>
<p><span style="text-decoration: underline;">Note:</span></p>
<p style="text-align: justify;">For this blog post, we will need two Salesforce Org. One will act as Identity provider and other will act as Service Provider. I have enabled My Domain and below are information</p>
<ul>
<li>https://jitendrazaa5-dev-ed.my.salesforce.com &#8211; <span style="text-decoration: underline;">Service Provider</span></li>
<li>https://jitendrazaa2-dev-ed.my.salesforce.com &#8211; <span style="text-decoration: underline;">Identity Provider</span></li>
</ul>
<p><strong>Enable My Domain</strong></p>
<p style="text-align: justify;">First step is to enable My Domain in Service Provider Organization. I would suggest name your org with suffix like &#8220;spProvider&#8221; and &#8220;ipProvider&#8221; to avoid confusion.</p>
<p><strong>Enable and setup SSO in Service provider Org</strong></p>
<p style="text-align: justify;">You can read this article for <a href="https://www.jitendrazaa.com/blog/salesforce/implement-saml-based-single-sign-on-sso-salesforce-as-identity-provider-idp-salesforce-as-service-provider-sp/">more detail</a> on using Salesforce as IDp and SP. Assuming, you already have basic knowledge of SSO, we will jump start.</p>
<p style="text-align: justify;">In Service provider Organization enable SSO by navigating to &#8220;Setup | Security Controls | Single Sign-On Settings&#8221;.</p>
<p style="text-align: justify;">Download &#8220;Self Signed Certificate&#8221; from Identity provider by navigating to &#8220;Setup | Security Controls | Certificate and Key Management | Create Self Signed Certificate&#8221;.</p>
<p style="text-align: justify;">Below image shows configuration of SSO in Service provider organization, In our case domain &#8220;jitendrazaa5-dev-ed.my.salesforce.com&#8221;.</p>
<figure id="attachment_4809" aria-describedby="caption-attachment-4809" style="width: 625px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/SSO-Setting-in-Service-Provider-Org.png?ssl=1"><img data-recalc-dims="1" decoding="async" class="size-large wp-image-4809" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/SSO-Setting-in-Service-Provider-Org.png?resize=625%2C302&#038;ssl=1" alt="SSO Setting in Service Provider Org" width="625" height="302" srcset="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/SSO-Setting-in-Service-Provider-Org.png?resize=1024%2C494&amp;ssl=1 1024w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/SSO-Setting-in-Service-Provider-Org.png?resize=300%2C145&amp;ssl=1 300w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/SSO-Setting-in-Service-Provider-Org.png?resize=624%2C301&amp;ssl=1 624w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/SSO-Setting-in-Service-Provider-Org.png?w=1308&amp;ssl=1 1308w" sizes="(max-width: 625px) 100vw, 625px" /></a><figcaption id="caption-attachment-4809" class="wp-caption-text">SSO Setting in Service Provider Org</figcaption></figure>
<p style="text-align: justify;">In above image Issuer is URL of identity provider and Entity Id is URL of current org which is Service provider.</p>
<p style="text-align: justify;">Once we informed Service provider Org that SSO is enabled on basis of federation Id, we need to make sure that Federation Id on user records on both Org must match else SSO will not work and those users will not able to use Canvas application.</p>
<p><strong>Create force.com Canvas application in Identity provider Org</strong></p>
<p>Navigate to &#8220;Setup | App Setup | Create | Apps | Connected Apps | New&#8221;</p>
<figure id="attachment_4810" aria-describedby="caption-attachment-4810" style="width: 625px" class="wp-caption aligncenter"><a href="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-application-Configuration.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-large wp-image-4810" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-application-Configuration.png?resize=625%2C920&#038;ssl=1" alt="Force.com Canvas application Configuration" width="625" height="920" srcset="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-application-Configuration.png?resize=696%2C1024&amp;ssl=1 696w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-application-Configuration.png?resize=204%2C300&amp;ssl=1 204w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-application-Configuration.png?resize=624%2C919&amp;ssl=1 624w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-application-Configuration.png?w=1228&amp;ssl=1 1228w" sizes="auto, (max-width: 625px) 100vw, 625px" /></a><figcaption id="caption-attachment-4810" class="wp-caption-text">Force.com Canvas application Configuration</figcaption></figure>
<p style="text-align: justify;">As you can see in above setting, Canvas application is enabled for Chatter and Mobile navigation and it uses Visualforce page of Service provider Organization.</p>
<p>Entity Id and ACS URL is copied from SSO settings of Service provided organization.</p>
<p><strong>Creating Visualforce page using Canvas SDK in Service Provider Organization</strong></p>
<p style="text-align: justify;">Instead of using any Heroku or external web based application, we will be using Visualforce page with Canvas SDK. For this, we need to download Canvas SDK from <a href="https://github.com/forcedotcom/SalesforceCanvasJavascriptSDK">this Github</a> repository and upload it as static resource. In below Visualforce page, we are simply reading Signed request from Identity provider Organization showing capabilities of Canvas SDK as well as we are displaying SessionId, OAuth token and refresh token of Service provider Organization.</p>
<p style="text-align: justify;">As Canvas application is configured to view from Chatter tab, Output will look like :</p>
<figure id="attachment_4811" aria-describedby="caption-attachment-4811" style="width: 669px" class="wp-caption alignleft"><a href="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-Application-Demo-with-Complete-Source-code.png?ssl=1"><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-4811" src="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-Application-Demo-with-Complete-Source-code.png?resize=669%2C452&#038;ssl=1" alt="Force.com Canvas Application Demo with Complete Source code" width="669" height="452" srcset="https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-Application-Demo-with-Complete-Source-code.png?w=669&amp;ssl=1 669w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-Application-Demo-with-Complete-Source-code.png?resize=300%2C203&amp;ssl=1 300w, https://i0.wp.com/www.jitendrazaa.com/blog/wp-content/uploads/2015/09/Force.com-Canvas-Application-Demo-with-Complete-Source-code.png?resize=624%2C422&amp;ssl=1 624w" sizes="auto, (max-width: 669px) 100vw, 669px" /></a><figcaption id="caption-attachment-4811" class="wp-caption-text">Force.com Canvas Application Demo with Complete Source code</figcaption></figure>
<ul>
<li> </li>
</ul>


<p></p>



<h2 class="wp-block-heading">Source code for Canvas in Salesforce</h2>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;apex:page showHeader=&quot;false&quot;&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;{!URLFOR($Resource.CanvasSDK,&#039;SalesforceCanvasJavascriptSDK-master/js/canvas-all.js&#039;)}&quot; /&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
        var sid=&quot;{!GETSESSIONID()}&quot;.substr(1,30) +&#039;...&#039;;
    	function refreshSR(){
        	Sfdc.canvas.client.refreshSignedRequest(function(data){
                if(data.status == 200){
                	var signedRequest = data.payload.response;
                    var part = signedRequest.split(&#039;.&#039;)&#x5B;1];
                    var obj = JSON.parse(Sfdc.canvas.decode(part));
                    updateDisplay(obj) ;
                }
            });
        }

    function updateDisplay(obj){
    	setValue(&#039;spSessionId&#039;, sid);
        setValue(&#039;ipOAuth&#039;, obj.client.oauthToken.substr(1,30)+&#039;...&#039;);
        setValue(&#039;ipUser&#039;, obj.context.user.fullName);
        setValue(&#039;ipOrg&#039;, obj.context.organization.name);
        setValue(&#039;ipRefresh&#039;, obj.client.refreshToken.substr(1,30)+&#039;...&#039;);
    }

    function setValue(eleId,val)
    {
       	var domEl = document.getElementById(eleId);
        if(domEl){
        	domEl.innerHTML = val;
        }
    }

    Sfdc.canvas.onReady(function(){
    	refreshSR();
    });
    &lt;/script&gt;

        &lt;b&gt; &lt;u&gt; Service Provider Org &lt;/u&gt;&lt;/b&gt;
        I am Canvas App from Salesforce Domain &lt;b&gt; Jitendra.zaa5@gmail.com &lt;/b&gt;
        User : {!$User.FirstName} {!$User.LastName}
        Org : {!$Organization.Name}
        Session Id : &lt;span id=&quot;spSessionId&quot;&gt;&lt;/span&gt;    

&lt;hr /&gt;

        &lt;b&gt; &lt;u&gt; Identity Provider Org  - Current Org &lt;/u&gt; &lt;/b&gt;
        User : &lt;span id=&quot;ipUser&quot;&gt;&lt;/span&gt;
         Org : &lt;span id=&quot;ipOrg&quot;&gt;&lt;/span&gt;
         OAUth Token : &lt;span id=&quot;ipOAuth&quot;&gt;&lt;/span&gt;
        Refresh Token : &lt;span id=&quot;ipRefresh&quot;&gt;&lt;/span&gt;

&lt;/apex:page&gt;
</pre></div>


<h3 class="wp-block-heading">Resources</h3>



<ul class="wp-block-list">
<li><a href="https://github.com/ccoenraets/salesforce-canvas-demo">Canvas example using Nodejs</a></li>



<li><a href="https://developer.salesforce.com/page/Force.com_Canvas">List of all Canvas resources</a></li>



<li><a href="https://resources.docs.salesforce.com/sfdc/pdf/canvas_framework.pdf">Developers guide</a></li>



<li><a href="https://github.com/forcedotcom/SalesforceCanvasJavascriptSDK">Github Canvas SDK repository</a></li>
</ul>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/salesforce/salesforce-to-salesforce-integration-using-canvas/feed/</wfw:commentRss>
			<slash:comments>13</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">4807</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.jitendrazaa.com @ 2026-06-12 13:17:17 by W3 Total Cache
-->