Integration: Uploading files to SharePoint tightly coupled to Salesforce metadata

This is a multi-part series where we discuss how to integrate SharePoint and Salesforce. There isn’t a one size fits all, I will share a few of the different ways we’ve done it in past projects.

  • Best In Class(es): Bringing Salesforce and Office 365 Together. Instead of forcing one platform to do it all, aim to leverage the best of both platforms: Salesforce and Office 365.
  • Case management in Salesforce, documents in SharePoint. We created a folder creation process to store case files in SharePoint and giving users the full breadth of document capabilities of SharePoint.
  • THIS POST: Uploading files to SharePoint tightly coupled to Salesforce metadata. We created a custom upload form to associate specific metadata from Salesforce to the file in SharePoint, along with providing Salesforce the references to the files.

Coming Up:


The first example might suffice for most needs, however, we came across a more targeted need. Lawyers could create dockets, which are official court correspondences for the case, then upload the document and have it tagged with the docket code from Salesforce. We couldn’t let them upload the file directly into a SharePoint library as the docket code and number would be unique for each docket. We didn’t want them to manually enter in the metadata either. Since there would be unique metadata per file, the default column metadata trick we did previously wouldn’t work here.

For this need, we went with a more custom approach. For starters, the docket creation screens in Salesforce were custom VisualForce pages, which was required for the overall functionality but also allowed us to complete the file upload portion of it as well. Upon creating a docket, the user would click a button to add files.

Button in Salesforce which opens a SharePoint page to upload files

Clicking Add Files would let the user upload files directly into SharePoint.

SharePoint in a popup window from Salesforce

Note the URL, that’s SharePoint! From here, users could upload files and specify additional metadata. Since this was a docket, we had to validate the file wouldn’t overwrite another file, so we check to make sure the file is legit.

validated files in SharePoint.jpg

When the files are uploaded, they are placed in a folder for this case, the metadata is set. Meanwhile the user gets a friendly upload status bar. Upon completion, the Salesforce page is notified of the file URLs, and that data is stored in the record and displayed to the user.

SharePoint files listed in Salesforce

We also had an event handler on the library, which would deny deleting files in the Dockets folder, across all cases. If they deleted a docket in Salesforce (which only admins could do) then the file would be deleted from SharePoint via the APIs.

High Level Design

salesforce to sharepoint metadata flow.jpg

Some technical details

  • Salesforce submits all of the metadata about the complainant, respondent, case, and docket(s) to a SharePoint list via a custom Azure API.
  • We leveraged the SharePoint PnP JavaScript library and jQuery in the pop window, to query the metadata, perform the necessary validation and upload the file to the library.
  • We used window.opener.postMessage to notify Salesforce, the opener, of the URLs of the uploaded files. Salesforce then wrote the URLs to the record.
  • The event handler is hosted in Azure, which denies users from deleting the files but allowing Salesforce to delete it via an API in Azure.

 

Advertisements

17 thoughts on “Integration: Uploading files to SharePoint tightly coupled to Salesforce metadata

Add yours

      1. David,
        Sorry for late reply. Yes, but I found it from CustomURLs settings page. You have written some web api to create entry in list and then you are calling from Apex class. I want to know how to do the deployment of web api to Azure?

        Thanks for your help.

        Like

      2. That’s a very large question with a large answer. I’m not sure we can cover this over email or the blog post here. I’d start with searching for web APIs in Azure to learn that piece, then create an API to connect to SharePoint. Sorry, I can’t provide more specific code…

        Like

  1. Sure David, If you could post that series, it will be helpful to me. Please help me for the below question. In that salesforce solution, file upload API is deployed to Azure and it is automatically uploading Web Registration Cards into SharePoint document library with every 2 to 3 minutes. I am unable to get the information from Salesforce or from Azure portal. Please guide me.

    Like

  2. David, I am trying to setup new site in new salesforce environment and I did the following operations. But I found the error to display the docket summary.

    1. Created new resource group in Azure
    2. Created new pubxml file to the existing docket solution
    3. Download the profile from Azure Portal for the newly created Resource Group
    4. Update the necessary details in pubxml file based on the profile and did the deployment from Visual Studio
    5. Added New Remote Site under Security Controls in Salesforce
    6. Updated the CUSTOM_URL section to point out new SharePoint site & docket URL

    Error: Content cannot be displayed: Expected DocketFileExtension.DocketSendError but found “invalid URL: https://test.sharepoint.com/sites/sitename/” at [line:1, column:44]

    Please help me.

    Like

      1. David – The error is displaying in the Docket Files layout. After click the Docket Name link for the case, it displays the above error. When I check the Developer Console, it provides the below error.
        23:26:23:398 CALLOUT_REQUEST [273]|System.HttpRequest[Endpoint=https://salesforcedeletedocketdev2.azurewebsites.net/api/dockets, Method=PUT]

        23:26:23:709 CALLOUT_RESPONSE [273]|System.HttpResponse[Status=Bad Request, StatusCode=400]

        23:26:23:709 USER_DEBUG [277]|DEBUG|Response Body: {“Message”:”ERROR”,”RequestID”:0,”Errors”:[“invalid URL: https://test.sharepoint.com/sites/obc-cases-dev2/“]}

        23:26:23:711 FATAL_ERROR System.JSONException: Expected DocketFileExtension.DocketSendError but found “invalid URL: https://test.sharepoint.com/sites/obc-cases-dev2/” at [line:1, column:44]

        Please help me on this.

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: