How To Perform Salesforce Testing
Tags: java, salesforce, webdev, beginners
Published: 2022-04-23 10:08:16

![](https://miro.medium.com/max/1400/1*l-zvThIBZgH5EUgY6-oYFg.jpeg)

No more long-winded discussions about Salesforce Testing

The key goal of any business is to ensure customer satisfaction. Businesses invest a lot of time and effort into satisfying the customer base with an emphasis on rapid and efficient customer interactions, thus underlining the need for efficient CRM products in the market.

What is CRM?
============

According to market leader [Salesforce](https://www.salesforce.com/eu/learning-centre/crm/what-is-crm/), a CRM can be defined as "a strategy that companies use to manage interactions with customers and potential customers. CRM helps organizations streamline processes, build customer relationships, increase sales, improve customer service, and increase profitability." It is also known as Customer Relationship Management (CRM).

CRM tools have been on the rise for the past couple of years and it is very important for growing a business. Some benefits of a CRM software are as follows:

-   Improving efficiency: Having a central data repository ensures better team collaboration, workflow, and project management.
-   Customer retention: By relying on a single source of truth, there is more confidence in working with customers which enhances customer relations.
-   Transparency: Everyone has an idea about the processes, and can work with more clarity and better teamwork
-   Increased sales: By streamlining the sales process, pipeline building a task automation and sales data analysis will significantly improve your sales

What is Salesforce?
===================

With a plethora of CRMs available in the market today, each provides its own set of benefits. However, Salesforce, the world's first cloud-based CRM remains the market leader in helping its clients sell, service, market, analyze, and connect with their clients in an affordable and hassle-free manner.

As per a [Gartner report](https://www.gartner.com/en/documents/4002572), the global CRM market grew from $61.6 billion in 2019 to $69.3 billion in 2020, reflecting an increase of 12.6%, and is currently the world's third-fastest growing segment in the IT space.

The Worldwide Semiannual Software Tracker by the International Data Corporation (IDC) has ranked Salesforce #1 in Customer Relationship Management Solutions for the eighth consecutive year running and its data clearly shows Salesforce rising head and shoulders above its competitors over the last few years.

This clearly highlights the need for Salesforce Testing in particular, and CRM testing in general to any QA Leaders intent on streamlining their process for a seamless customer experience.

What is Salesforce testing and why test salesforce applications?
================================================================

The main goal of Salesforce testing is to test the customized application features, rather than those built into SalesForceDotCom (SDFC).

Since one of the most important USPs of SFDC is the fact that everything in it can be customized based on user requirements, Salesforce testing of these features serves to guarantee that any enhancements or custom features will not fail in production, or throw a spanner in the works of other elements in the SF application.

Testing the custom features in SDFC is important because:

-   It allows us to check if the code is functional.
-   It helps verify that the application can cater successfully to client needs based on business requirements.
-   It helps catch issues early in testing, making them easier to fix.
-   With the help of functional flows, we can obtain a report on the basis of test case statuses.

Initially, Salesforce services were offered using its Classic Platform, popularly known as Aloha. This was in vogue during the 2000s and was supplemented by Force.com which was SF's first PaaS (Platform as a Service) offering. This could allow clients to build custom applications on top of Salesforce without any additional software.

In more recent years, SF has offered the Lightning platform to its clients which comes with a number of additional functionality and security features, as well as an improved UI experience.

For the purposes of this article, we shall be dealing with the Salesforce Lightning platform.

The Scope of Salesforce Testing
===============================

Like any other platform, Salesforce applications also undergo the same phases of the software testing life cycle as shown below.

![](https://miro.medium.com/max/1024/0*MWCghEXL6o_iwF_s.png)

A short description of these types with examples is discussed below:

This is done mainly by developers themselves to test the code they wrote. These tests are not restricted to any specific user scenarios and tend to be highly specific.

Example: A developer has scripted a password input text field with its validation ar (8 characters long, must contain special characters.); makes a unit test to test out this one specific text field (has a test that only inputs 7 characters, no special characters, empty field)

Testers / QA professionals mainly perform this. It revolves around use cases and functional system requirements. Testers generally have no understanding of the code (also known as Black Box Testing).

Example: A tester writes a test case to ensure that the password is accurately saved in the database after generating one. This ensures that the code written by the developer is integrated with the system's database.

User Acceptance Testing

Acceptance testing determines if a software system meets all predetermined specifications. It evaluates if the system complies with business, technical, and aesthetic requirements so that business stakeholders and end-users can be satisfied alike.

Acceptance tests are generally divided into User Acceptance Testing and Business Acceptance Testing. The former checks to ensure that the product is meeting all performance standards from the users' perspective while the latter establishes that the [software aligns with business goals](https://www.browserstack.com/guide/how-to-set-goals-for-software-quality-assurance) and requirements.

Example: The client tests a particular functionality, like adding a customer to the CRM on a custom module on-site

Both the QA team and end-users perform testing in the production environment.

Example: Checking for customer creation and deletion processes in the CRM after go-live.

This can be done in both a manual as well as an automated manner. The main purpose of this [type of testing](https://www.browserstack.com/guide/types-of-testing) is to check whether any changes made to a custom functionality have not impacted other functionalities and everything works as before

Example: Checking for the login functionality after a new UI has been designed for the login page.

Of these many types of testing, the [Selenium Unit tests](https://www.browserstack.com/guide/unit-testing-frameworks-in-selenium) need to be written in the APEX programming language used by Salesforce, whereas the others can be done either manually or using an automation test tool like [Selenium](https://www.browserstack.com/selenium).

How to perform Salesforce Unit Testing in APEX
==============================================

The @isTest is used to define classes and methods that only contain code used for testing the application.

A sample format would be

@isTest private class MyTestClass { @isTest static void test1() { // Implement test code } @isTest static void test2() { // Implement test code } }

Below are a few examples of implementing Unit tests for some common Salesforce constructs:

A trigger is an APEX script that executes prior to or posts a Data Manipulation Event (DML). These allow the performance of custom actions before or after a record has undergone insertion, update, or deletion.

@isTest public class TriggerTestClass { static testMethod void testMethod1() { // Perform DML here only } }

For Standard Controllers

A standard controller takes a record and places it in a variable that it makes available to a page.

@isTest public class ExtensionTestClass { static testMethod void testMethod1() { Account testAccount = new Account(); testAccount.Name='Test Account record' ; insert testAccount; Test.StartTest(); ApexPages.StandardController sc = new ApexPages.StandardController(testAccount); myControllerExtension testAccPlan = new myControllerExtension(sc); PageReference pageRef = Page.AccountPlan; // Add your VF page Name here pageRef.getParameters().put('id', String.valueOf(testAccount.Id)); Test.setCurrentPage(pageRef); //testAccPlan.save(); call all your function here Test.StopTest(); } }

Some best practices for Unit testing in Salesforce include:

-   Test class should be annotated with @isTest.
-   Classes with @isTest annotation can't be an interface or enum.
-   Test method should be static and no void return type.
-   Starting with the Salesforce API 28.0 test method can not reside inside non-test classes.
-   To deploy to production at least 75% code coverage is required

Manual and Automation Tests for Salesforce
==========================================

Once the developers are happy with the [test coverage](https://www.browserstack.com/guide/code-coverage-vs-test-coverage) through Unit Tests in Salesforce, it is time to perform a variety of [manual or automation tests](https://www.browserstack.com/guide/manual-vs-automated-testing-differences). However, before we start testing the SF applications, we must ensure to set up a Sandbox that allows us to perform these tests in isolation.

[Salesforce Sandbox](https://help.salesforce.com/s/articleView?id=sf.create_test_instance.htm&type=5) testing can be done on a variety of Sandbox types like:

-   Developer Sandbox: This is intended for development and testing in an isolated environment, This contains a copy of the production environment's configuration.
-   Developer Pro Sandbox: This can host larger sets of data than the vanilla Developer Sandbox, and has the capacity for increased development and quality assurance tasks and for integration testing or user training.
-   Full Sandbox: This is meant as a dedicated [testing environment](https://www.browserstack.com/guide/what-is-test-environment), and supports [performance testing](https://www.browserstack.com/guide/performance-testing), load testing, and staging. They are intended as a replica of the production org, including all data, such as object records and attachments, and metadata. However, the significant lag due to the refresh interval makes them unsuitable for development purposes.

A Variety of licenses can be purchased for these Sandbox types as per your requirement.

Pro Tip: *No emulator or simulator can replicate *[*real user conditions*](https://www.browserstack.com/real-user-conditions-testing-on-browserstack)*. Software needs to be tested on real devices to work in real-world circumstances such as a low battery, incoming calls, weak network strength, and so on. If an in-house lab is not accessible, opt for a *[*real device cloud*](https://www.browserstack.com/real-device-cloud)*.*

Manual Tests in Salesforce
--------------------------

Manual testing, as the term suggests, refers to a test process in which a QA manually tests the software application in order to identify bugs. To do so, QAs follow a written test plan that describes a set of unique test scenarios. The QA is required to analyze the performance of the web or mobile application from an end user's perspective.

For the purposes of this article, take a simple positive [test scenario](https://www.browserstack.com/guide/how-to-create-test-scenarios) of a successful login to the Salesforce site and [write a brief test case](https://www.browserstack.com/guide/how-to-write-test-cases) accordingly.

Test Steps:

1.  The user navigates to the [Salesforce login page](https://login.salesforce.com/?locale=us).

![](https://miro.medium.com/max/1024/0*qA6Pf5AA1_WOqW5B.png)

1.  In the 'email' field, the user enters their registered email address.
2.  The user enters the registered password.
3.  The user clicks 'Login.'
4.  The user is redirected to the Home page

Test Scenario: To authenticate a successful user login on Salesforce.com

Automated Tests in Salesforce
-----------------------------

Automation Tests in Salesforce can be done using a variety of tools. However, we will consider test automation using Selenium With Java for the purposes of this article.

Selenium is compatible with multiple operating systems like Windows, Linux, Solaris, and Macintosh. It also supports multiple browsers like Chrome, Safari, IE, Edge, and Firefox. It is used to [automate functional tests](https://www.browserstack.com/automated-functional-testing). Also, Selenium is easy to integrate with tools like Jenkins, Maven, and Docker to achieve a [continuous testing approach](https://www.browserstack.com/guide/continuous-testing-strategy-for-devops). Tools like [TestNG](https://www.browserstack.com/guide/testng-framework-with-selenium-automation) and [JUnit](https://www.browserstack.com/guide/junit-and-automation-testing) further help in structuring the selenium tests for easy maintainability and generating reports.

For the purposes of this test, we shall build upon the example for manual testing shown above, and add a few features. This test will demonstrate how to use [Selenium with Java](https://www.browserstack.com/guide/selenium-with-java-for-automated-test) to create a custom field for a custom object.

Step 1: Login to the Salesforce

To launch the website in a browser of your choosing, set the system properties to the path of the required driver for the browser. Since this example uses Google Chrome, it should be set to the [ChromeDriver](https://www.browserstack.com/guide/run-selenium-tests-using-selenium-chromedriver). The code for the same is as follows

Webdriver driver = new ChromeDriver(); System.setProperty("webdriver.chrome.driver", "Path of the chrome driver");

Maximize the browser for a clear picture of test cases being executed using the following command.

driver.manage.window.maximize();

Step 2: Navigate to salesforce.com

driver.get("https://login.salesforce.com");

It will appear as seen below

![](https://miro.medium.com/max/1024/0*LDQgMcSi1s2Neun3.png)

Step 3: Enter Username and Password using the following command

driver.findElement(By.xpath("//input[@id='username']")).sendKeys("<Enter email>"); driver.findElement(By.xpath("//input[@id=password]")).sendKeys("<Enter Password>");

Step 4: Click the Login Button using the following command

driver.findElement(By.xpath("//input[@class='button r4 wide primary']")).click();

Since you may encounter some issues while loading the page, add a wait to let the page load completely

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

This will lead to the Home Page as seen below

![](https://miro.medium.com/max/1024/0*8GPYA_qvbs6tbefi.png)

Step 5: Find the Quick Find Search Field in the UI on the home screen and enter object in the Quick Find Search field.

![](https://miro.medium.com/max/1024/0*ZBg2stRVdytzDf-c.png)

driver.findElement(By.xpath("//input[@class='quickfindInput version2 ']")).sendKeys("object");

Step 6: Click appearing after entering object in the Quick Find Box

driver.findElement(By.xpath("//a[@id='CustomObjects_font']")).click();

![](https://miro.medium.com/max/1024/0*VRpOZiJiGSbdtJ0j.png)

Step 7: Click on the " Create New Objects Link "

driver.findElement(By.xpath("//a[@value='New Custom Object']")).click();

![](https://miro.medium.com/max/1024/0*DxZSg7Qxzf9niruO.png)

Step 8: Choose the Label text box to input the object name and do the same for Plural Label

driver.findElement(By.xpath("//input[@id='MasterLabel']")).sendKeys("abc"); driver.findElement(By.xpath("//input[@id=PluralLabel']")).sendKeys("abc's");

![](https://miro.medium.com/max/1024/0*zYwdMTkxiDqLUWIO.png)

Step 9: Click on Save button at the end of the page

driver.findElement(By.xpath("//a[@value=' Save ']")).click();

![](https://miro.medium.com/max/1024/0*YAsicU2-DZObFTot.png)

The Custom Object created can be seen below

![](https://miro.medium.com/max/1024/0*a1HS_nf2Ya7By3ML.png)

Best Practices of Salesforce Testing
====================================

Now that it is identified what to test, where to test, and how to test in terms of testing salesforce applications, let's discuss some best practices for testing salesforce effectively.

A proper test strategy and test plan are absolutely critical for Salesforce testing as it encompasses many components and business processes. A clear view of the high-level objectives, the stakeholders present, the different phases of testing involved, and the tools to be used must all be determined in this phase.

Salesforce offers a variety of Sandbox options for isolated Salesforce Sandbox testing. To satisfactorily test business-critical functions, all systems should be properly integrated in the sandbox so that proper integration testing can be performed in real-time scenarios like on production.

Read More: [How do you ensure maximum test coverage?](https://www.browserstack.com/guide/how-to-ensure-test-coverage)

Automating critical and often repeated business processes, like a checkout or order fulfillment flow, in Salesforce saves lots of time when testing. Salesforce supports several types of API endpoints that can be used for automation testing. API endpoints can be automated by using tools like Postman, REST-Assured & Soap UI.

-   Navigating through frames
-   Executing against dynamic content
-   Handling tables
-   Object dependency
-   Heavy DOM structure and shadow DOMs
-   Driving data
-   Reusability
-   Long steps for end-to-end testing

Common Challenges in Salesforce Testing
=======================================

Some of the core challenges that QA professionals face during Salesforce automation are:

-   SF Classic supports the [latest IE 11 version](https://www.browserstack.com/test-in-internet-explorer), but it is not supported by Lightning.
-   SF Lightning does not support private browsing in the latest version of firefox but classic does
-   Certain features in Salesforce, like the Standard mail merge or extended mail merge (Salesforce Classic only Feature), and some client applications like Connect Offline work only on the Internet Explorer.

It is best to choose the correct [test automation framework](https://www.browserstack.com/guide/best-test-automation-frameworks) that provides solutions to these challenges. However, an even bigger challenge is the issue of successful [cross browser testing](https://www.browserstack.com/live) in Salesforce regardless of whether it is done manually or through an automation framework.

Since Salesforce customers have an option of using the Classic or the Lightning platform features, there is an amount of variation involved in performing some tasks based on the platform of choice as well as the browser being used. For example:

Since all organizations cannot allocate funds for infrastructure to test have a massive test environment for Salesforce Testing, cloud-based platforms like Browserstack to implement cross-browser testing for all your Salesforce testing needs

Salesforce is a leading CRM, equipped with a large feature set, that can be customized and reconfigured to suit an organization's business needs. However, only focusing on developing SF modules is not enough. Salesforce testing is critical in ensuring customer satisfaction and delivering processes that not only work seamlessly but also enable the maximum leverage of Salesforce's unique capabilities to ensure customer success.