Over a million developers have joined DZone.

7 Steps to Integrate Salesforce With Sharepoint

A tutorial on how to use Microsoft Azure to integrate Salesforce with Sharepoint.

· Integration Zone

Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud, brought to you in partnership with IBM.

The buzzword of this digital era is “cloud”. It is a concept which has totally captured the market. Working areas are becoming geographically dispersed with every passing day. So cloud concept is gaining momentum where you can work and collaborate from anywhere and everywhere.

Image title

Speaking of Salesforce and Microsoft SharePoint, both are the undisputed kings in their own domains. Where Salesforce is declared as the world’s number 1 Customer Relationship Management (CRM) platform, on the other hand, Microsoft SharePoint is one of the most sturdy content and document management systems around.

While both of these systems have their strengths, they lack some features as well. SharePoint is an exquisite document management system, it is mostly used as a secure document repository for intranet portals and websites. Salesforce, on the other hand, is known for its versatility along with being a CRM platform. It has an ever-growing list of added features and functionalities, it has gradually evolved into a complete sales and marketing management platform but then it lacks storage abilities like SharePoint.

Most companies are in search of a strong well-managed document management platform, they mostly have Microsoft 365 but do not spend extra bucks on Salesforce, so, in this case, the best solution is to integrate Salesforce with Sharepoint to multiply their strengths.

SharePoint Salesforce Integration Using Microsoft Azure:

There are a number of ways by which you can carry out this integration like using third party integration service, or a third party system installer adapter, Microsoft Azure hosted service, etc.

The Steps Are as Follows:

Step 1: Authentication request is sent to the adapter by Salesforce.

Step 2: The adapter forwards the request to SharePoint.

Step 3: After authenticating the information, SharePoint passes the security token for further use.

Step 4: The adapter receives the token and thereafter sends it to Salesforce.

Step 5: The token is used as an authentication key, Salesforce then send a request to view the accessible files and folders.

Step 6: The Adapter then forwards the request along with the token and subsequently receives an output. It then again passes on to the Salesforce installation.

Step 7: Either of the two things happen: First being either the token expires and the process is repeated again or secondly using the same token, more requests are sent and received.

Salesforce Handling Step 1:

To enable this Sharepoint Salesforce integration, the main point is to host a running service on Microsoft Azure and allow it to interact with SharePoint. It is hosted on the cloud and hence accessed via URL. So the Salesforce methods requesting authentication token are as follows. This codes reaches out to the Azure service using URL and receives the authentication token.

public static String getToken(){
        String token;
        token = SharePointAPIUtility.SharePointAPIGet
      system.debug('token>>> '+token);
           if(token != null){
        return EncodingUtil.urlEncode(token.replaceAll('"',''), 'UTF-8');
        return null;
        public static String SharePointAPIGet(String endpointUrl,String username, String password){
          HttpRequest httpRequestObject = new HttpRequest();
        Blob headerValue = Blob.valueOf(username + ':' + password);
        String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
          httpRequestObject.setHeader('Authorization', authorizationHeader);
          system.debug('httpRequestObject>> '+httpRequestObject);
        Http http = new Http();
          HttpResponse httpResponse ;
              httpResponse = http.send(httpRequestObject);
          if(httpResponse != null && httpResponse.getStatus() == 'OK' 
             && httpResponse.getStatusCode() == 200){
        return httpResponse.getBody();
        }else if(httpResponse != null){
        return 'SharePoint Server Error: Status '+ httpResponse.getStatus()+'
          Status Code '+ httpResponse.getStatusCode() +' Body 
      }catch(CalloutException ce){
        throw ce;
      }catch(Exception ex){
        throw ex;
        return null;

Azure Taking Care of Step 2, 3 and 4:

After receiving the authentication token, Azure authenticates the login.

public bool Login(string email, string password)
      //throw new Exception("This is error!!");
      bool validateLogin = false;
      List<string> MessageList = new List<string>();
      //string decryptedPassword = Encryption.Decrypt(encryptedPassword);
      if (email == ConfigurationManager.AppSettings["Email"] 
          && password == ConfigurationManager.AppSettings["Password"])
     string authInfo = email + ":" + password;
     authInfo = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(authInfo));
     //authInfo = Encryption.Encrypt(authInfo);
     System.Web.HttpContext.Current.Response.AppendHeader("Authorization", "Basic " + authInfo);
     // Insert User Token
     MessageList.Add("Login Successful");
     validateLogin = true;
     MessageList.Add("Invalid Username Or Password");
      return validateLogin;

Salesforce Performing Step 5:

Once Salesforce has authentication token, it uses that same token to request files and folders from the adapter. After completion of sending a request, it again uses the Azure service URL to hit the service.

public static List<String> getAllFolders(SharePoint365APIParser objSharePoint365APIParser){
          list<String> objFolders = new list<String>();
        if(objSharePoint365APIParser.folders != 
           null && objSharePoint365APIParser.folders.size()>0)//null check
        for(SharePoint365APIParser.folders sp:objSharePoint365APIParser.folders){
        return objFolders;
      }catch(Exception ex){
        throw ex;
        return null;
        public static List<String> 
          getFilesByFolder(String folderName, SharePoint365APIParser objSharePoint365APIParser){
        if(objSharePoint365APIParser.folders != null && objSharePoint365APIParser.folders.size()>0)
        for(SharePoint365APIParser.folders sp:objSharePoint365APIParser.folders){
                      if(sp.files.size() > 0){             
                          return sp.files;
                          return new list<String>();
          }catch(Exception ex){
        throw ex;
        //}//end running test loop
        return null;

Azure Handling Step 6:

After Salesforce has received the authentication token and is logged in on SharePoint, the Azure service parses the file in the following way:

     public Folders GetResourceData()
      Folders fld = new Folders();

          using (ClientContext clientContext = 
                 new ClientContext("https://yourprojectname.SharePoint.com/Resources"))
             SecureString passWord = new SecureString();
             foreach (char c in "TestPassword".ToCharArray()) passWord.AppendChar(c);
             clientContext.Credentials = new SharePointOnlineCredentials("Test@test.com", passWord);
             Web rootweb = clientContext.Web;
             var folders =
             string pString = @"\Resources\";
             fld.folders = new List<Folders>();
             fld.name = "Resources";
             foreach (Microsoft.SharePoint.Client.Folder myFolder in folders)
                  fld.folders.Add(GetFoldersAndFiles(myFolder, clientContext, pString));

      catch (Exception)
      { fld.name = "Some error happened."; }
      return fld;
     private Folders GetFoldersAndFiles(Microsoft.SharePoint.Client.Folder mainFolder,
                                        ClientContext clientContext, string pathString)
      Folders fldr = new Folders();
      List<string> fls = new List<string>();
      fldr.folders = new List<Folders>();
          clientContext.Load(mainFolder, k => k.Files, k => k.Folders);
      foreach (var folder in mainFolder.Folders)
     string folderPath = string.Format(@"{0}{1}\", pathString, folder.Name);
     if (folder.Name != "Forms")
             fldr.folders.Add(GetFoldersAndFiles(folder, clientContext, folderPath));
      foreach (var file in mainFolder.Files)
      fldr.files = fls;
      if (mainFolder.Name != "Forms")
     fldr.name = mainFolder.Name;
      return fldr;

Good luck with the integration steps of the two powerful systems SharePoint and Salesforce. You may get in touch with me if you encounter any issues.

Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud, brought to you in partnership with IBM.

salesforce,salesforce integration,crm,sharepoint,microsoft azure,azure

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}