Hey Techies,

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

You might be wondering, “Where do I even start?” Fear not! This step-by-step guide will take you from creating a SharePoint site to mastering API callouts. It’s your ultimate resource, designed to save you time and effort. Here’s what you need to know.

Two Approaches to Accessing SharePoint Files in Salesforce

There are two primary ways to integrate SharePoint with Salesforce:

Use Standard Files

API Callouts to Create Your 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

image for create site in sharepoint

Now choose the type of site you want to create. In this case we will be using Team site.

Guide for create site

Now, add the site details and your team members.

Form for add new site

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,
  • Reference – points to external files stored outside Salesforce. 
  • 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 

Files Connect Settings

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

Permission Sets

After creating permission set go to System Permissions and enable “Files Connect Cloud

Permission Sets

After that go to manage assignments and add user.

Setup permission sets
Files Connect

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. 

Auth Provider
  • 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,

https:// Company.sharepoint.com/sites/MyTestSite/_layouts/15/OauthAuthorize.aspx

See, I told you I got you covered. 🙂

Step 4: 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,

https://Company.sharepoint.com/sites/MyTestSite/_layouts/15/appregnew.aspx Here, Generate Client Id and Secret by clicking the “Generate” button.

Generate client id and secret
  • 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. <Salesforce_Domain_Name>

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

https://Company.sharepoint.com/sites/MyTestSite/_layouts/15/appinv.aspx

Over here we need to give Permission Request XML.

Give permission request for xml

<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.

External data source

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

Validate External Data Source

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.

Setup Permission Sets
Setup permission sets

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.

Grant external data permission

Step 10: Create Named Credential

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

Create named credentials

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.

Integrated SharePoint

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.

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.

callout:<Named_Credential>/_api/web/GetFolderByServerRelativeUrl(\’/sites/<Your_SharePoint_SiteName>/Shared%20Documents\’)/Folders’)

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.

callout: <Named_Credential>/_api/web/GetFolderByServerRelativeUrl(\’/sites/<Your_SharePoint_SiteName>/Shared%20Documents\’)/Files)

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.

callout:<Your_Named_Credential>/_api/web/GetFolderByServerRelativeUrl(\’/sites/<Your_SharePoint_SiteName> /Shared%20Documents\’)/Files/add(url=\”+fileName+’\’, overwrite=true)

Create folder into SharePoint

callout:<Your_Named_Credential>/_api/web/GetFolderByServerRelativeUrl(\’/sites/ <Your_SharePoint_SiteName>/Shared%20Documents\’)/folders

Author

Maitry Soni

I’m a Salesforce professional with three years of hands-on experience in the platforms. Passionate about technology and innovation, I enjoy sharing knowledge through blogging about insights on Salesforce and its applications. You can find me @LinkedIn.