Skip to Content
Technical Articles
Author's profile photo Pavithra Ramachandra

Integrate SAP IRPA 2.0 with Salesforce to extract data records using API calls

CRM applications like Salesforce, Oracle are becoming a mandatory part of organizations to run their business successfully. However, for managing any CRM software, companies must allocate a large amount of resources. This increase in the overall expenditure due to resource allocation stops many small businesses from taking advantage of CRMs. One of the most compelling ways to improve the overall effectiveness of Salesforce or any other CRM is by using robotic process automation services.

With the help of SAP intelligent robotic process automation 2.0, a business user can automate their daily activities and proactively get in touch with the customers.

Introduction

In this blog post, we are going to see, how to integrate Salesforce system with SAP Intelligent RPA using API calls and fetch data from Salesforce system. Salesforce provides a large set of APIs to allow calls from external applications to access salesforce database.

We are going to use REST API calls to interact with salesforce system. By creating and configuring connected apps, API services can be enabled at the Salesforce system. A connected app is an application that allows external application to integrate with Salesforce using APIs and standard protocols.

Steps to create and configure the connected apps can be found in one of my blogs, Salesforce Integration with SAP IRPA 2.0 to insert data records using API calls

Create Automation

First step would be login to SAP Intelligent RPA Cloud factory, go to projects tab and create a new project.Enter the project name and description and click on create. This will create a project and the project is opened in a new window.Under Content tab, click on create and select Automation.Provide the name of the automation and description in the pop-up window and click on create. This will create an automation with an empty workflow.

Ensure that the below dependencies are added in your automation project.A custom script is added to the workflow as the first step in the workflow, to set up a secure connection to salesforce.

For us to establish a secure connection to salesforce, we need to get the Authentication. Authentication is used for getting access token and instance URL. To get those details, we need to set up a login request URL.

In the login URL, client_id, client_secret, grant_type, user id and password must be entered in the format shown below.

https://[LoginDomain].salesforce.com/services/oauth2/token?grant_type=password&client_id=[Your consumer key]&client_secret=[Your consumer secret]&username=[salesforce Username]&password=[Salesforce Password]

Click on Edit script and custom editor window opens. Add the below code to fetch the access token from Salesforce.Method type used is ‘POST’. ‘irpa_core.request.call()’ is used to make the API call. Response of the API call will have the access token, instance URL, and token type details. Token type and Access token are concatenated and stored in a separate variable. Access token details are returned to the workflow by creating output parameter in the custom script.Another custom script is added to extract data records from the Salesforce system. Input parameters are created to pass instance URL, Access token and Object to which the data records are to be inserted, to the custom script from the workflow.Custom script contains the below code.Request URL will be in the format ‘[instance URL]/services/data/[Salesforce Version]/sobjects/[sObjectName]’. In our case, we are extracting the data records of sObject ‘Accounts’. Method type will be ‘GET’, as we are fetching the data records from salesforce system. Header parameters contain the content type and authorization parameters. Access token fetched from the first step is passed as Authorization parameter.’ irpa_core.request.call()’ is used to make the API call. Response of the API call is returned to the workflow by creating an output parameter ‘ReadResult’.

Data fetched from the previous API call is extracted into an excel file. Open Excel instance and Open workbook activities are added to open the excel file. Set Active cell activity is added to set cell number ‘A1’ as active cell.Push values activity is used to enter the column headers in the excel file. Set second row in the first column as the active cell using Set active cell activity.Create a counter variable to count the number of records that have been extracted. Add ‘For loop’ activity, to loop through the fetched data records and process them. Data values are pushed into the excel one by one using the ‘Push value’ activity. After every data record that’s been filled, get the row number, and set the active cell to the first column of the next row. Add ‘Set’ activity to increment the counter at the end of every loop.Once all the data records have been processed, ‘Log message’ activity is added to display the total number of data records that have been extracted.Add Close workbook and Close excel instance activities to save and close the excel file.

Below are the screenshots of the complete workflow.

Here is the screenshot of data records in Salesforce account that has been used in this project. There are 16 data records available in the sObject ‘Accounts’.Below is the screenshot of the excel file with the extracted data records. All the 16 records have been extracted.Below screenshot is of the message that displays the total number of data records that have been extracted.Here is the project demo video.

Conclusion

Seamless integration to different systems is possible with simple steps using SAP Intelligent RPA features.

The intention of this blog post is to get customers, business managers and RPA developers to get into thinking about using SAP Intelligent RPA 2.0 in numerous automation scenarios by using simple steps for achieving great results.

I hope you found this tutorial helpful. Please provide feedback in the comment section and feel free to ask any questions in the SAP Intelligent RPA Q&A area (link for reference: https://answers.sap.com/tags/73554900100800002142)

Assigned tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.