DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 7)
  • How to Identify Bottlenecks and Increase Copy Activity Throughput in Azure Data Factory
  • Cross-Platform Integration: Enabling Seamless Workflow Between AI, Microservices, and Azure Cloud
  • Strategic Insights Into Azure DevOps: Balancing Advantages and Challenges

Trending

  • What’s Got Me Interested in OpenTelemetry—And Pursuing Certification
  • Monoliths, REST, and Spring Boot Sidecars: A Real Modernization Playbook
  • Analyzing Techniques to Provision Access via IDAM Models During Emergency and Disaster Response
  • Navigating Change Management: A Guide for Engineers
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. 7 Steps to Integrate Salesforce With Sharepoint

7 Steps to Integrate Salesforce With Sharepoint

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

By 
Davis Kerby user avatar
Davis Kerby
·
Jan. 13, 16 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
28.6K Views

Join the DZone community and get the full member experience.

Join For Free

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;
      if(!Test.isRunningTest()){
        token = SharePointAPIUtility.SharePointAPIGet
          ('http://testingalgoworks.azurewebsites.net/Api/Values/GetAuthToken',
           'Test@test.com','TestingPassword');
        }
      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){
        try{
          HttpRequest httpRequestObject = new HttpRequest();
          httpRequestObject.setEndPoint(endpointUrl);
          httpRequestObject.setmethod('GET');
        Blob headerValue = Blob.valueOf(username + ':' + password);
        String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
          httpRequestObject.setHeader('Authorization', authorizationHeader);
          httpRequestObject.setTimeout(120000);
          system.debug('httpRequestObject>> '+httpRequestObject);
        Http http = new Http();
          HttpResponse httpResponse ;
          if(!test.isRunningTest())
              httpResponse = http.send(httpRequestObject);
          if(httpResponse != null && httpResponse.getStatus() == 'OK' 
             && httpResponse.getStatusCode() == 200){
              system.debug('httpResponse.getBody();
                           >>>>'+httpResponse.getBody()+'httpResponse.getBody();>>>>');
        return httpResponse.getBody();
        }else if(httpResponse != null){
        return 'SharePoint Server Error: Status '+ httpResponse.getStatus()+'
          Status Code '+ httpResponse.getStatusCode() +' Body 
          '+httpResponse.getBody();
        }
      }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;
      }
      else
      {
     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){
        try{
          list<String> objFolders = new list<String>();
        if(objSharePoint365APIParser.folders != 
           null && objSharePoint365APIParser.folders.size()>0)//null check
        for(SharePoint365APIParser.folders sp:objSharePoint365APIParser.folders){
                  objFolders.add(sp.name);
        }
        return objFolders;
      }catch(Exception ex){
        throw ex;
        }
        return null;
        public static List<String> 
          getFilesByFolder(String folderName, SharePoint365APIParser objSharePoint365APIParser){
      //if(!test.isRunningTest()){
        try{
        if(objSharePoint365APIParser.folders != null && objSharePoint365APIParser.folders.size()>0)
        for(SharePoint365APIParser.folders sp:objSharePoint365APIParser.folders){
                  if(sp.name.equalsIgnoreCase(folderName)){
                      if(sp.files.size() > 0){             
                          return sp.files;
                      }else{
                          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:


[AuthorizeWebAPI()]
     [HttpGet]
     public Folders GetResourceData()
     {
      Folders fld = new Folders();
      try
      {

          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 =
   rootweb.GetFolderByServerRelativeUrl("/Resources").Folders;
             string pString = @"\Resources\";
                 clientContext.Load(folders);
             clientContext.ExecuteQuery();
             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);
     clientContext.ExecuteQuery();
      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)
      {
     fls.Add(file.Name);
      }
      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.


SharePoint azure Integration

Opinions expressed by DZone contributors are their own.

Related

  • Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 7)
  • How to Identify Bottlenecks and Increase Copy Activity Throughput in Azure Data Factory
  • Cross-Platform Integration: Enabling Seamless Workflow Between AI, Microservices, and Azure Cloud
  • Strategic Insights Into Azure DevOps: Balancing Advantages and Challenges

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!