Showing posts with label Connected App. Show all posts
Showing posts with label Connected App. Show all posts

Thursday, 13 May 2021

Integration of Salesforce Chatter with SharePoint Online

INTRODUCTION 

When working on one of the requirements for a manufacturing sector project for a client based in Atlanta, Georgia, USA, we came across a requirement where we had to develop a solution by integrating Salesforce with SharePoint. The basic need was to save feedback/comments from SharePoint to custom object in Salesforce. 

Comment should contain user name same as in Salesforce Chatter. Responses received from either of the platform, Salesforce or SharePoint; should be in sync. 

CHALLENGE

The main challenge was that SharePoint users are not licensed users within Salesforce. And API provided by chatter saves comment or post to chatter for only Salesforce licensed user. These users were not in sync with both Salesforce and SharePoint. 
 
The other challenge was to display comments from Salesforce into SharePoint. Connect API provides very complex response from Salesforce and it was not easy to map the field values in SharePoint. 

APPROACH

To address these issues, we took an approach of configuring a custom object in Salesforce to save comments. With a Master-detail relationship, we linked this custom object (which was created to save comments) to its parent object. 

To get more insight about the technical approach, have a look at the below explanation and screenshots. 

Let’s assume that we have an object (e.g., Account) which we consider as a parent object. We want to add comments related to the each record of that object. 

Now, users from SharePoint are going to add their comments to the records of this object to keep track of approval status. Let’s not forget that these users are not licensed Salesforce users. 

SharePoint users add their comments from SharePoint UI and with use of REST API, it will be stored in custom object in Salesforce, which is related to our parent object - Account. 

To store these comments from SharePoint, Salesforce connected app credentials were used for authentication and authorization.

Configuration of custom object for Chatter is shown in below screenshot:

Data fetched through REST API from SharePoint, would be displayed as shown in below screenshot.

SUMMARY 

By configuring custom object in Salesforce & using REST API, we can easily integrate data from 3rd party applications used by non-Salesforce users by its username or email id.

If you have any questions you can reach out our Salesforce Consulting team here.

Friday, 4 December 2020

How to use lightning component on any external platform using Lightning Out Feature

Overview:

In this blog, we will go through steps for using Lightning Out to run Lightning Components outside of the Salesforce server. We will be running the lightning component on Localhost server.


Pre-requisites:

  • Configuration in Salesforce for Connected App and CORS.
  • Lightning Dependency App in Salesforce.
  • We will be using the Node Js to make a server-side call.
  • OpenSSL to create a Self-Signed Certificate.
Solution:

Follow the below steps to operate your lightning component from localhost.


Step 1: Whitelists the localhost URL in CORS from Salesforce

The Same-Origin-Policy restricts the browser to make a request to/from the same domain. So to make your origin (external application) able for sending XMLHttpRequest to Salesforce, we will have to whitelist domain of the external application in CORS from Salesforce as shown in the below screenshot.



Step 2: Create a Connected App in Salesforce  
From many ways to authenticate Salesforce from an external website, let's use the most secure way which is OAuth. To use OAuth, you need to create a Connected App. Connected App provides different types of permission settings to allow external websites to use after authentication. Do not forget to set the callback URL in your Connected App.

 

 

Step 3: Create Lightning Dependency App  

To make this app accessible outside of Salesforce, make sure you do not forget the below points, 

  • The Lightning App must be globally accessible, which means that access must be defined as global. 
  • The ltng:outApp must be extended to allow you to use it outside the lightning framework / Salesforce. 
  • To make use of the Aura component as part of Lightning Out, it should be defined as the aura:dependency.

<aura:application access="Global" extends="ltng:outApp">
      <aura:dependency resource="c:LCSearchFirst" />     
      <aura:dependency resource="c:LCSearchDataTable"/>  
</aura:application> 


Step 4: Generate an X.509 Certificate using OpenSSL 

Generate a valid Self-Signed Certificate for localhost development by running two commands shown in a given reference link.

These commands will create .pem and .crt files, which we will use in the Node.js application to provide a secure connection between two servers.

Step 5: Create Node.js application to make a server call

Create a Node.js application that will use to run on the localhost to make a server call. In this application, use X509 and allow CORS for the localhost.



Step 6: Create a page to host Lightning Component 

To use the Lightning component in your external application, you need to import Lightning out JavaScript in the page hosting your Lightning component, refer to the below markup :  


<script src="https://YOURDomain.lightning.force.com/lightning/lightning.out.js"></script> 

Output:


You can find the complete source code of this blog post from Github


Conclusion:

    

By following the above steps, you can run or host any Lightning Component from your Salesforce server to the localhost. You can implement the same for other platforms also such as Heroku, SharePoint.


If you have any questions you can reach out our Salesforce Consulting team here.