Automating Salesforce Contact Creation Process with Robocorp Lab - ⋮IWConnect

Automating Salesforce Contact Creation Process with Robocorp Lab

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, 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 provides 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.

Figure 1: Tasks.Robot File

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:

Figure 2: Add New Keyword

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.

Figure 3: Task – Open Salesforce Website

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

Figure 4: Salesforce Login Page

Login to Salesforce Website

The next step will be adding a new keyword and call 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.

Figure 5: Login to Salesforce Code

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.

Figure 6: Salesforce Contact Form

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:

Figure 7: Create a New Contact – Keyword

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 done in the code from above.

This is how the whole process should look like now:

Figure 8: Create New Contact

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.

Figure 9: RPA.Excel.Files – Library

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.

Figure 10: Fill the Contact Form from Excel File – Keyword

This is how the excel file looks like:

Figure 11: Excel File

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.

Figure 12: Read Worksheet as Table

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.

Figure 13: Loop through each row of the table

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.

Figure 14: Populate Contact from Excel file

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

Figure 15: Populate Contact Form from Excel file

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.

Figure 16: Contact Details

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 how the complete code looks like:

Figure 17: Software Robot Code

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:

Figure 18: Robocorp Lab Linked Account

Navigate to Robocorp Cloud and create a new Organization.

Figure 19: Create 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.

Figure 20: Add Robot to Robocorp Cloud

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

Figure 21: 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.

Figure 22: Create Process

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

Figure 23: Add Step

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

Figure 24: Run Process

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.


Aleksandra Stojanovski
Aleksandra Stojanovski

Senior QA Consultant