How to Create Test Data in Salesforce Using Smock-it?

Manually creating test data in Salesforce is both resource-intensive and a slow grind. Most development teams that rely on manual practices face compliance issues and remain dependent on other teams for datasets that reflect real-world scenarios.

Without efficient test data creation, release cycles drag, compliance risks rise, and development teams struggle to deliver features on time. All of this eventually hinders overall business efficiency.

This is where Salesforce test data generation tools like Smock-It can help. As a lightweight Salesforce CLI plugin, Smock-It automates test data creation in Salesforce, ensuring the data is realistic, structured, and fully compatible with Salesforce schemas.

Unlike other tools that create Salesforce test data only to end up failing in production, Smock-It generates GDPR and CCPA-compliant test data that matches unique business requirements. 

Challenges Faced in Salesforce Test Data Generation

Before we explore how to create Salesforce test data using Smock-it, let’s discuss the data generation challenges that most teams face (and that you might be facing!).

  1. Slow and Time-consuming: Creating meaningful test data manually requires days of preparation, which slows down actual testing and extends project timelines.

  2. Accuracy and Reliability: Inconsistent or randomly generated test data lead to unreliable test results and frequent failures. For instance, when test data doesn’t account for complex field dependencies, such as hierarchical account relationships or territory management rules, it results in gaps in test coverage and missed edge cases.

  3. Privacy and Compliance Risks Using customer data for testing introduces compliance risks under GDPR and CCPA.

  4. Dependencies on others: To create synthetic test data in Salesforce, QAs and developers rely on other departments, which creates bottlenecks and delays in testing cycles.

  5. Scalability issues: Salesforce’s complex data structure makes it difficult to create large and precise test data for large implementations.

Generate test records in minutes

Smock-It eliminates the slow, manual process of test data creation in Salesforce. With just a few CLI commands, teams can quickly generate high-quality, relational test data tailored to their business needs.

Here’s what makes Smock-It a go-to tool for Salesforce test data generation:

1. Easy Test Data Generation

Smock-It streamlines test data creation using a reusable template system. Simply define your objects, fields, and formats once, then generate thousands of records in minutes with just a few commands.

2. Data Refresh and Automation

Smock-it automates data refresh cycles, ensuring test data is always up to date without manual intervention. The latest version takes automation to the next level with built-in GitHub Actions integration, enabling seamless CI/CD workflows without extra effort.

3. Salesforce Schema Compatibility

Smock-It ensures Salesforce schema compatibility by supporting standard and custom objects/fields while generating structured datasets that reflect real-world business logic.

4. Compliance and Privacy

By creating synthetic data that mirrors real-world scenarios, Smock-It eliminates the risk of using production data and ensures compliance with privacy regulations. 

5. Advanced Customization

Users have granular control over data output, specifying fields and record volumes. This flexibility supports varied test cases from localized applications to high-volume enterprise environments.

6. Enterprise-Grade Scalability

Whether for small development teams or enterprise-scale testing, Smock-It effortlessly generates large datasets, making it ideal for everything from unit tests to full-system simulations.

Create test Data in Salesforce using Smock-it.

Before generating test data, Smock-It requires a simple setup. This involves installing the plugin and configuring a template that defines what kind of data to generate.

Step 1: Install Smock-It

To begin, make sure you have the following prerequisites installed:

  • Node.js (version 18.0.0 or above)

  • Salesforce CLI (sf CLI)

Once your environment is ready, open your terminal and install the Smock-It plugin using the following command:

sf plugins install smock-it

This will add Smock-It to your Salesforce CLI environment.

📖Also Read: How to Install Smock-It in Easy Steps?

Step 2: Initialize the Template

Templates are at the heart of Smock-It. They define which Salesforce objects to include, the number of records to generate, and how relationships between those records should be structured.

To initialize a template, run:

sf smockit template init

This command will launch a guided questionnaire to help you define your test data requirements. You’ll be prompted to answer a few key questions, such as:

  • Provide a template name

  • Select the output format (CSV, JSON, or DI)

  • Specify the number of test records

  • List objects for data creation (standard or custom)

  • Customize settings for individual sObjects (y/n)

Once you've answered these, a JSON data template will be created and saved in the template folder inside the data-gen directory.

📖 Read our step-by-step installation guide on GitHub

📖 Check out the template init questionnaire 

Step 3: Generate Test Data

Once the template is ready, it’s time to generate the test data based on your defined configurations.

To do this, run the following command:

sf smockit data generate -t <templateFileName> -a <aliasOrUsername>

  • -t specifies the template file you created in the previous step.

  • -a refers to the Salesforce alias or username of the org where you want to push or preview the generated data.

Note: For Data Insertion (DI), your target org must be authenticated so that validations can be performed correctly.

You can authenticate multiple orgs and use their alias or username during data generation.

Unique data will be generated each time, even when using the same template.

To use the same data across orgs, use the Data Upload feature described in Step 4.

📖 Learn how to generate test data from a template

🔐 See how to authenticate your Salesforce org

Step 4: Data Upload

In certain scenarios, you may need to use the same test data across multiple orgs. The Data Upload feature in Smock-It enables this by allowing you to reuse previously generated data.

To upload existing data into a different org, use the following command:

sf smockit data upload -u <fileName> -s <sObject> -a <orgAliasOrUserName>

  • -u refers to the previously generated data file

  • -s specifies the Salesforce object

  • -a refers to the alias or username of the target org

Note: You can upload any data file saved in the output folder inside the data-gen directory.

Github document- upload test datasets into multiple Salesforce orgs

Smock-It Use Cases: From Template Creation to Data Generation

Let’s walk through how templates are created from start to finish. We’ll explore two practical use cases to generate test data, demonstrating the process in action.

Use Case 1: Create 200 Records for Account, Contact, and Opportunity with Output in DI and JSON Formats

This example demonstrates how to generate 200 test records for standard Salesforce objects, Account, Contact, and Opportunity, with outputs in both Data Insertion (DI) and JSON formats.

Steps to Execute

1. Initialize the Template

Run the sf smockit template init command in your terminal to start the guided setup:

2. Provide Input for the Questionnaire

  • Template name: accountDataTemplate

  • Exclude namespace(s): (leave blank)

  • Select output format [csv, json, di]: di, json

  • Specify test data count: 200

  • List Objects (API names): account, contact, opportunity

  • Customize settings for individual sObjects?: n

  • Validate added sObjects and fields from your org?: n

Generated Template Preview

{
  "namespaceToExclude": [],
  "outputFormat": ["di", "json"],
  "count": 200,
  "sObjects": [
    { "account": {} },
    { "contact": {} },
    { "opportunity": {} }
  ]
}

Important 💡

Once the template is ready, run the following command to generate the data using your org alias or username:

sf smockit data generate -t accountDataTemplate_data_template -a <aliasOrUsername>

If you skipped validation during template creation, Smock-It will automatically perform it during data generation.

Use Case 2: Generate 150 Account and 50 Lead Records with Custom sObject Settings

This use case demonstrates data generation using object-level customization, where each object has a predefined record count. Data is generated based on these individual settings instead of global configurations.

Steps to Execute

1. Initialize the Template

Run the sf smockit template init command on the CLI

2. Provide Input for the Questionnaire

  • Template name: account_leadTemplate

  • Exclude namespace(s): (Leave blank)

  • Select output format [csv, di, json]: di, json

  • Specify test data count: 200

  • List Objects (API names): account, lead

  • Customize settings for individual sObjects? Y

Override the global settings for object: account

[account - count] Set number of records: 150
[account - fieldsToExclude] List fields to exclude: N/A
[account - fieldsToConsider] List fields to include: N/A
[account - pickLeftFields] Generate for remaining fields? true

Override the global settings for object: lead

[lead - count] Set number of records: 50
[lead - fieldsToExclude] List fields to exclude: N/A
[lead - fieldsToConsider] List fields to include: N/A
[lead - pickLeftFields] Generate for remaining fields? true

  • Override global settings for another object? N

  • Validate added sObjects and fields from your org? N

Template Generated

{
  "namespaceToExclude": [],
  "outputFormat": ["di", "json"],
  "count": 200,
  "sObjects": [
    {
      "account": {
        "count": 150,
        "pickLeftFields": true
      }
    },
    {
      "lead": {
        "count": 50,
        "pickLeftFields": true
      }
    }
  ]
}

3. Generate the test data using the command:

sf smockit data generate -t account_leadTemplate_data_template.json -a alias/username

📖 Tip: Check out the Smock-It Template Use Case Guide on GitHub for more examples and insights into advanced test data generation.

Conclusion

Smock-It addresses the daily challenges QA teams encounter when preparing test data by reducing time and effort while ensuring compliance and accuracy. With its ability to handle complex data relationships, auto field inclusion, conditional data, multiple output formats, and enterprise-scale demands, it’s a great proposition for anyone looking for a reliable tool for Salesforce test data generation.

Haven’t tried Smock-It yet? Now is the perfect time to save countless hours and streamline your Salesforce testing process.

Let’s Talk!

Drop a note to move forward with the conversation!

Abhinav Gupta

First Indian Salesforce MVP, rewarded Eight times in a row, has been blogging about Salesforce, Cloud, AI, & Web3 since 2011. Founded 1st Salesforce Dreamin event in India, called “Jaipur Dev Fest”. A seasoned speaker at Dreamforce, Dreamin events, & local meets. Author of many popular GitHub repos featured in official Salesforce blogs, newsletters, and books.

https://abhinav.fyi
Previous
Previous

Smock-it GitHub Actions: Instant Salesforce Mock Data for CI/CD!

Next
Next

Is Salesforce Experience Cloud a Fit for Nonprofits?