Skip to main content
No Result Found
Connect & Get help from 6000+ developers on our Discord community. Ask the CommunityAsk the Community

Variables and functions

Learn how to use local variables, global variables, and functions to reuse test data across multiple steps, making your tests flexible and easy to maintain.

Variables make your tests flexible, readable, and easy to maintain. There are two types of variables in Salesforce Test Automation:

  • Local variables: Used within a single test to store and reuse values.
  • Global variables: Shared across multiple tests in your project.

In addition to variables, you can use Functions to generate random data dynamically for testing purposes.

Use variables to eliminate hardcoded values, centralize data, and make your tests easier to update.

Sample use case: Instead of hardcoding login credentials in every test step, create variables called email and password. Reference these variables in your test steps, so you only need to update the value in one place if it changes. This makes your tests easier to maintain and reduces errors from inconsistent data.

Create a local variable

Local variables let you reuse values within the same test. You can create them directly from the test editor.

To create a local variable:

  1. While creating a test, click the @ icon in the command input field. It opens the variable options menu. Select Create Variables from the menu.
    Variable options menu
  2. In the Create variable dialog:
    • Enter the Name of the variable (for example, Login email)
    • Enter the Value of the variable (for example, user@example.com)
    • (Optional) Click Add Function to generate dynamic values instead of static values. Refer to the Add functions for dynamic data section. Create variables option
  3. Click Save.
  4. Alternatively, you can convert any existing value in a test step into a variable by clicking the Convert to variable icon next to the value. Convert to variable

You can now reference this variable in other steps within the same test by typing @ and import it.

To delete a local variable, remove its first occurrence from the test step where it was created.

Create a global variable

Global variables help you share data across multiple tests and maintain consistency throughout your project.

To create a global variable:

  1. Go to Data configuration > Global variables in the sidebar on the home page. Global variables section
  2. Click + Create variable.
  3. In the Create global variable dialog:
    • Enter the Name of the variable (for example, Login ID)
    • Enter the Value (for example, admin@company.com) Create global variable
  4. Click Create.

The global variable is now available for use in any test within your project.

You cannot create global variables in the test editor. You can only create them in the Global variables section on the Salesforce Test Automation dashboard.

Manage global variables

In the Global variables section, you can view all global variables. The USED IN column shows how many tests use each variable.

To delete a global variable:

  1. Click the … (three dots) icon next to the variable.
  2. Perform any of the following actions:
    • Edit variable: Edit the name and value of the variable.
    • Delete variable: Delete the variable. Edit or delete global variable

Import variables in test steps

To use a variable in your test:

  1. In the test editor, type @ at the location where you want to use a variable.
  2. Select Import Variables from the menu. Import variables menu
  3. In the Import variables dialog, select the Local or Global tab to view the available variables. Select local or global variable
  4. Select the variable you want to use. The variable is added into your test step. Imported variable

Add functions for dynamic data

Functions allow you to generate random data dynamically, which is useful for testing scenarios that require unique values such as emails, passwords, or dates.

To add a function:

  1. While creating a variable, click Add Function in the Create variable dialog. Add function dialog
  2. In the Add function dialog, select a data type from the available options:
    • Alphabet: Generates random alphabetic strings
    • Number: Generates random numeric values
    • Email: Generates random email addresses
    • Password: Generates random passwords
    • Date: Generates date values
  3. Configure the function parameters:
    • For Alphabet: Set the string length (max 100 characters)
    • An example of the generated value is shown in the dialog
  4. Click Add function.

The function generates a new random value each time the test runs, ensuring unique data for each execution.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle