Integrating SharePoint with Salesforce: A Comprehensive Guide for Techies

si2tech blog

Hey Techies,
Are you and your team finding it challenging to manage SharePoint files directly within the Salesforce system? Don’t worry I have got you covered! Let’s dive in and harness the best of both worlds by integrating Salesforce with SharePoint.

But hey, I bet you’re thinking, “Where do I even begin?” Don’t worry, that’s where this step-by-step manual comes into play! This blog has you covered from creating a SharePoint site to mastering callouts – it’s your ultimate guide, no question! It’s a real time-saver, so you won’t need to spend hours searching elsewhere.

So basically, there are two approaches to accessing SharePoint files in Salesforce.
1. Use standard Files.
2. API Callouts to Create your own LWC component for file. Yes, you read it right – your very own LWC Component.

For both the approaches, you will need to set up Files Connect, Permission Sets, External Data Sources, Named Credentials, and Auth Providers.

So, Let’s start:
Step 1: Create SharePoint site
Firstly, we need to create one SharePoint site. So, for that follow below steps:
open SharePoint -> Create Site -> Select site type -> Add details

Now choose the type of site you want to create. In this case we will be using Team site.
si2tech Enteprise-Solutions
Now, add the site details and your team members.
si2tech members

Step 2: Files Connect

First of all, what’s Files Connect?

  • Files Connect is a tool.  Using Files Connect Salesforce users can access, share, and search external data from systems like Quip, Google Drive, SharePoint, or Box.
  • It gives 2 choices for file sharing,
    1. Reference – points to external files stored outside Salesforce.
    2. Copy – stores a copy of external files in Salesforce. If files are shared with a Chatter group, all group members can access the files, even if they lack access to the external system.


Go to files connect and change the setting as following steps,
Go to Setup -> Search -> Files Connect -> Enable Files Connect

si2tech services

Step 3: Create Permission Set

In order to access external files and folders, we need to provide the Files Connect permission to the user, for that we will make permission set and assign it to concerned user.
So, the below steps would be necessary:
Setup -> Permission Sets -> New -> System Permissions -> Enable Files Connect Cloud -> Manage Assignments -> Add Assignment -> Select User -> Assign

si2tech services
After creating permission set go to System Permissions and enable “Files Connect Cloud”
si2tech services
After that go to manage assignments and add user.
si2tech services
si2tech services

Step 3: Create Auth. Provider

Auth. Provider is important for authentication.
Steps for creating Auth. Provider are:
Setup -> Auth. Provider -> New -> Provider Type = Microsoft Access Control Service -> Add Details As mentioned -> Save.

si2tech services
  • For Saving Auth. Provider, Client Id and secret are important. So, enter dummy details for this step. These 2 fields will be edited after some steps.
  • We have to make Authorize Endpoint URL using the following URL.

https://<Your_SharePointDomain>.sharepoint.com/sites/<Your_SharePoint_SiteName>/_layouts/15/OauthAuthorize.aspx
For example,

See, I told you I got you covered.

Next step would be to create Token Endpoint URL for that use following formula,

https://accounts.accesscontrol.windows.net/<Your_SharePoint_Domain>.onmicrosoft.com/tokens/ oAuth/2?resource=00000003-0000-0ff1-ce00-000000000000/<Your_SharePoint_Domain>. sharepoint.com@<Your_SharePoint_Domain>.onmicrosoft.com

Example:
https://accounts.accesscontrol.windows.net/Company.onmicrosoft.com/tokens/oAuth/2?resource=00000003-0000-0ff1-ce00-000000000000/Company.sharepoint.com@ Company.onmicrosoft.com
After saving this, a callback URL will be generated. Which will be used for Registering SharePoint App.

Step 5: Register SharePoint App

Go to the following URL for SharePoint App Registration:

https://<Your_SharePoint_Domain>/sites/<Your_SharePoint_SiteName>/_layouts/15/ appregnew.aspx

Example,

si2tech services
  • In the redirect URI copy-paste the Callback URL from Auth. Provider:
    For example, https://<Your_Salesforce_Domain>/services/authcallback/<Auth_Provider_Name>
  • In App Domain give: www.
    For example,
    www.mySFAccount-dev-ed.develop.my.salesforce.com (FROM callback URL).

After that click create. we will get client id, secret and other details which we will need.

Step 6: Granting the Permission

SharePoint app needs permission.

For that, go to the following URL for granting the Permission to app:

Formula -> https://<SharePoint_Domain>/sites/<SharePoint_Site>/_layouts/15/appinv.aspx

Over here we need to give Permission Request XML.

si2tech services

<AppPermissionRequests>

<AppPermissionRequest Scope=”http://sharepoint/content/sitecollection” Right=”FullControl”/>

</AppPermissionRequests>

Here, we are giving full access to the site.

After clicking on create, the app will redirect to one page over there we need to click “Trust it “.

Now copy and paste client Id and Secret and add in Auth. Provider consumer key and secret.

Step 7: Configure External Data Sources

Hmm… Firstly, what is External Data Source?

It represents the metadata associated with an external data source. Create external data sources to manage connection details for integration with data and content that are stored outside your Salesforce org.

Go to Setup -> Search -> External Data Sources -> New External Data Source -> Select Type = Files connect: Microsoft SharePoint Online -> Select Previously Created Auth Provider -> Insert other details as shown in picture -> Save -> Validate and sync.

si2tech services
Now, validate external data source, and Sync it.by selecting the external object.
si2tech services

Step 8: Change Object Settings from permission set

Now, edit the permission set for that follow these steps:

Previously created permission set -> Object Settings -> Click on Object Name -> Edit -> Give Read Access -> Save.

si2tech services
si2tech services

Step 9: Grant External Data Source Access from Permission set

Previously created permission set -> External Data Source Access -> Edit -> Add Previously created External Data Source -> Save.

si2tech services

Step 10: Create Named Credential

Go to Setup -> Search -> Named Credential -> Create New.

si2tech services

Set the details as mentioned in the image. Here, we need to give the callback URL from Auth. Provider. Also, Select the previously created Auth. Provider in the authentication provider. And we are ready…!!!

We need to follow all these above steps for both standard and custom approaches.

In order to access files via standard way, Go to Files and we will be able to see SharePoint documents.

si2tech services

API Callouts

For creating our very own LWC component, we just need to use these below callouts and woah we are good to go,

For this custom approach, we need to create the salesforce org user in SharePoint. Then, add that user as a member of our SharePoint site.

1. Get Folders

To retrieve folder names from a specific SharePoint folder we can use the following URL. It will go to the directory as mentioned in the URL and fetch all the available folder names.

2. Get Files

To obtain files from a certain SharePoint folder, use the below endpoint URL which lists all the file’s names which are there in that folder.

3. Upload File into SharePoint

Whenever, there is a requirement to upload a file into SharePoint from salesforce we can use the following endpoint URL. Over here, this URL will create one file by a given name at a location provided in the callout. Also, there are 2 options when it comes to duplicate files.

1. overwrite=true -> this will overwrite the original file with the updated file.

2. overwrite=false -> this won’t upload the file again.

4. Create folder into SharePoint

Maitry-Soni

Author

Maitry Soni