Automating Salesforce Contact Creation Process with Robocorp Lab

26 Jan, 2021 | 8 minutes read

Introduction

Robocorp Lab is a Python-based open-source RPA tool founded in 2019, used for automating repetitive tasks and eliminating human intervention. Compared to other RPA tools this is a new tool, constantly working on improvement. Automated processes can be built with hundreds of Python– extensible libraries. It can be also connected to third-party applications and triggered from external services with their open APIs.

Robocorp supports Browser Automation, API automation, and Desktop application automation, and all software robots can be easily managed and orchestrated from Robocorp Cloud. Robocorp Cloud is a dashboard for monitoring software robots, centralized distribution of robots, and providing traceability to Robot operation.

Automation of Salesforce Contact Creation Process with Robocorp Lab

Imagine having an Excel spreadsheet with thousands of records that should be entered as Contacts in the Salesforce platform. This could take many hours of manual work. Robotic Process Automation can help this process to be completed in minutes. So, let’s go step by step and see how the Salesforce Contact Creation process can be automated with Robocorp Lab.

Build Robocorp Software Robot

The installation process for Robocorp Cloud is pretty much straight forward, you will only have to find the downloaded .exe file, execute it and wait for the installer to complete. Once you have installed it, you are ready to start building it.

On the starting screen of Robocorp Lab click on “Create new Robot”, give a name to your robot and you are ready to start building it.

Open tasks.robot file, by default this file has two cells, one is for Settings and the other is for Tasks. “Settings” cell is used for library definition and references to other files and in “Tasks” cell the tasks for the robot are defined. We can add as many additional cells as we need for our process. Each cell can be edited, duplicated, and executed individually. New cells can be added by clicking on the “+” button on the toolbar and they can be removed by clicking the “Scissors” button.

Let’s move on to real process automation, the creation of Salesforce Contact from an excel spreadsheet.

Add New Keyword

To open the Salesforce website, a new keyword should be added. As mentioned above the new keyword can be added by clicking on “+” button. At this moment an empty cell is created so let’s add some code to it.

Copy and paste this code into the empty cell:

*** Keywords ***Open Salesforce Website

This means that we are giving a name to this keyword and in this case, the name will be “Open Salesforce Website”.

Since in this case, we will need to open the Browser the following library is needed: ”RPA.Browser”. So, add the following code into the Settings cell:

Library           RPA.Browser

Once we have added the “RPA.Browser” library we can use its keyword “Open Available Browser” to navigate to the Salesforce website. Before adding this keyword, we must follow some of the Robocorp rules like we need to have at least two empty spaces before the keyword. So, it should look something like this:

In order to check whether the process is working, the “Tasks” cell should be renamed into something meaningful like “Insert Contact Data in Salesforce”, add the “Open Salesforce Website” keyword and click on “>>” to run the robot. It should open the Salesforce website. In the “Task” cell we are calling all keywords that should be executed.

If everything works as it should, it should navigate to the salesforce login page asking for credentials.

Login to Salesforce Website

The next step will be adding a new keyword and calling it “Login to Salesforce”. The locators of the elements from the HTML web page should be specified under this keyword. In this case we need locators for: username, password and login button. As an element locator, we can use: id, css, xpath etc. It’s up to you what you are going to use. The “RPA.Browser” library provides an “Input Text” keyword that can fill in text fields. This keyword takes two arguments:

  • Locator Argument – Tells where to input
  • Value Argument – Tells what to input

In this case, these are the ID locators:

  • Username id: username
  • Password id: password
  • Login id: Login

So, we can use the “Input Text” keyword in the following way to populate username, password and to click on the Login button.

Finally add “Login to Salesforce” keyword in “Tasks” run the robot and you should be successfully logged in to Salesforce and redirected to Contact Creation page.

Populating the Contact Form

In order to populate the Contact form, the same approach should be followed as for the Login form. Element Locators will be needed for First Name, Last Name, Phone, Email, and Title.

This time we will use XPath selectors. A new keyword for filling in the contact form should be created, named properly, and filled with Input Text locator arguments and values. It should look like this:

In case when the robot can’t find the contact form, it might need some sleep to be added before trying to input text into the form.

If the “Create New Contact” keyword is added to the “Tasks” cell, after execution the robot will populate the salesforce Contact Form with the values that we have provided above in the “Create New Contact” keyword. In this case, the Contact form should be populated with values from an Excel spreadsheet, so some changes should be made in the code from above.

This is how the whole process should look like now.

Using Excel Data for Filling Contact Form

In this step, the robot should read the Excel file and that can be done by using the “RPA.Excel.Files” library. So, this library should be imported under the “Documents” cell.

Create a new keyword and name it “Fill The Contact Form Using Data From The Excel File” and now the robot can open the excel file using the “Open Workbook” keyword, we just need to pass the file name.

This is how the excel file looks like:

The robot should read the data from the excel file, which can be done with the “Read Worksheet As Table” keyword. The data will be saved into a variable that will be called ${contacts}. Because the excel file contains headers in the first row, the header parameter should be passed as TRUE. In the end, the excel file can be closed by using the “Close Workbook” keyword.

In case there is more than one record in the Excel file, the robot should loop through the rows of the table and call it each time passing the individual row to it.

This means that the robot will loop through each row of the table, and for each record, it will create a new contact. We need to move one step back at the “Create New Contact” keyword. We expect the ${contacts} argument to be a list of named items. This means that if we want to access the FirstName property, we should write ${contacts}[FirstName] and replace the fixed value with this. And this should be done with all input values from the Contact form.

This is how the whole Robocorp Code should look at this point:

Now the robot can create Contacts using the Excel spreadsheet data.

Assertions

As a final step, some assertions should be added just to make sure that the contact is created with appropriate data. So, let’s add a new keyword and name it “Assert Contact”. With the help of the keyword “Go to”, the created contact can be easily accessed, this is the first step that should be done to start with the assertion.

Next, we need to identify the element locators of the fields that should be asserted. Let’s say that we need to assert Name, Title, and Phone.

After the element locators are identified, the keyword “Element Text Should Be” can be used to verify the text of each element. It should look like this:

Element Text Should Be    xpath://*[@id=”leftColumn-42″]/slot/slot/slot/flexipage-component2/slot/records-lwc-highlights-panel/records-lwc-record-layout/forcegenerated-highlightspanel_contact___012000000000000aaa___compact___view___recordlayout2/force-highlights2/div[2]/div[4]/slot/slot/force-highlights-details-item[1]/div/p[2]/slot/lightning-formatted-text     QA Engineer

The same approach should be followed for Name and Phone. At this point, the software robot is completed. If this robot is executed it will create Contact in Salesforce by using data from the excel spreadsheet, and as a final step it will assert several values of the created Contact.

This is what the complete code looks like:

Configuring Robots in Robocorp Cloud

Before we move to Robot Configuration in Robocorp Cloud, first we need to create an account at the following location: https://id.robocorp.com/signup

After the successful account creation, you will have to link Robocorp Lab with your Robocorp Cloud Account.

That can be done by clicking on “Log in to Robocorp Cloud” on the Robocorp Lab begin screen.

If successfully linked, you should see your email as in the picture below:

Navigate to Robocorp Cloud and create a new Organization.

After you have successfully created a new organization navigate to it and create a new workspace. Next, you can move to the Robots section and click on the “New Robot” button. Provide a name for the robot and leave the other options as they are.

Now it’s time to upload the Robocorp code to Robocorp Cloud. Open Robocorp Lab and click on “Upload to Robocorp Cloud”.

Select a workspace and the robot that you’ve created and then click on “Upload Robot”.

Now the Robot should be successfully uploaded to Robocorp Cloud. It’s time for process creation. In Robocorp Cloud navigate to the Workforce section and click the “New Process” button. Provide a name to the process.

In the steps section, click on the “Add Step” button, select the robot, and leave the environment as it is.

In order to run the process, under the Workforce section click the “Run Process” button. And that’s it.

Conclusion

Searching for Robotic Process Automation software can be an expensive process that requires deep pockets. The most popular RPA tools often provide more than what’s necessary for companies with advanced functionalities. Also, there are a lot of free and open-source RPA tools out there, with Robocorp being one of them.

Robocorp is a relatively new RPA tool that needs improvement compared with the paid RPA tools.

It is a promising tool, with an excellent support team available at any time to help. As an open-source tool has some limitations that might be overcome soon. Robocorp supports Browser Automation, API automation, Desktop application automation, and all software robots can be easily managed and orchestrated from Robocorp Cloud for free.

There is huge potential with Open Source Robotic Process Automation. The best part about these tools is that they create an open framework for users to combine with different tools to innovate. As part of modernizing technology, everyone needs to adopt these open-source RPA tools in automating business processes.