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

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

Blog at WordPress.com.

Up ↑

%d bloggers like this: