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 bank on manual practices face compliance issues and remain dependent on other teams to receive datasets that reflect real-world scenarios.
Without efficient test data development, 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.
Salesforce Test Data Generation Challenges
Before we explore how Smock-It creates test data for Salesforce, let’s discuss Salesforce test data generation challenges that most teams face ( and that you might be facing!).
Slow and Time-consuming: Creating meaningful test data manually requires days of preparation, which slows down actual testing and extends project timelines.
Accuracy and Reliability: Inconsistent and randomly generated test data leads to unreliable test results and failures in production. For example, generated test data doesn’t account for complex field dependencies like hierarchical account relationships or territory management rules and hence incomplete test coverage.
Privacy and Compliance Risks Using customer data for testing introduces compliance risks under GDPR and CCPA.
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.
Scalability issues: Salesforce’s complex data structure makes it difficult to create large and precise test data for large implementations.
How Smock-It Helps in Salesforce Test Data Generation?
Smock-It follows a series of steps to generate synthetic Salesforce test data that’s automated, relational, precise, and fully compliant for your unique scenarios. Plus, its generated templates offer full customization, allowing teams to tailor test data to their exact needs.
Here’s how what makes Smock-It a go-to tool for Salesforce test data generation:
1. Easy Test Data Generation
Smock-It simplifies test data creation with a reusable template system. Define your objects, fields, and formats once, and generate thousands of records in minutes with 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, languages, 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.
Quick Tip 💡
With our advanced Salesforce Test Data Generator, you can generate up to 2,00,000 records for free. Give Smock-It a try!
Smock-It Prerequisites
Before you get started with Salesforce test data generation using Smock-It, make sure you have the following installed on your machine:
Salesforce CLI - A command line interface to manage your Salesforce orgs.
Node.js (18.0.0 or later) - Required to run Smock-It scripts and manage dependencies.
Mockaroo API Key - To generate realistic, diverse and synthetic test data.
Installing Smock-It - A Quick Overview
To install Smock-It, follow these simple steps:
Ensure that you have Salesforce CLI and Node.js (v18.0.0 or later) installed.
Install Smock-It via Salesforce CLI:
sf plugins install smock-itVerify installation:
sf plugins
📖Also Read: How to Install Smock-It in 5 Easy Steps?
Smock-It Use Cases
Let’s dive into Salesforce test data generation with Smock-It using a use-case-based approach with the init and more commands. This will help you get familiar with custom templates and get started with them fast.
Use Case 1
Create 200 Records for Account, Contact, and Opportunity with output in DI and JSON formats.
Steps to Execute
Run the command `sf template init` on the CLI, and it will prompt you with a questionnaire.
Provide Input for the questionnaire
Provide a template name (e.g., account_creation): accountDataTemplate
Exclude namespace(s) (comma-separated, e.g., mynamespaceA, mynamespaceB):
Select output format [csv, json, di]: di, json
Choose a language for test data: en
Specify test data count (e.g, 5) (default: 1): 200
List Objects(API names) for data creation (default: lead): account, contact, opportunity
Customize settings for individual sObjects? (Y/n) (default: n): n
Validate added sObjects and fields from your org?(Y/n) (default: n): n
Template Generated
{ "templateFileName": "accountDataTemplate_data_template.json", "namespaceToExclude": [], "outputFormat": ["di", "json"], "language": "en", "count": 200, "sObjects": [ { "account": {} }, { "contact": {} }, { "opportunity": {} } ] }
Important 💡
Once the schema is configured as per requirements, use the sf data generate command with the template name and alias/username: sf data generate -t accountDataTemplate_data_template -a alias/username. If validation is skipped, Smock-It automatically performs it during data generation.
Use Case 2
Create 150 Account, 50 Lead records in English, applying sObject settings
Steps to Execute
Step 1: Run the command sf template init on the CLI, and it will prompt you with a questionnaire.
Step 2: Provide Input for the questionnaire
Provide a template name (e.g., account_creation): account_leadTemplate
Exclude namespace(s) (comma-separated, e.g., mynamespaceA, mynamespaceB):
Select output format [csv, di, json]: di, json
Choose a language for test data: en
Specify test data count (e.g, 5) (default: 1): 200
List Objects(API names) for data creation (default: Lead): account, lead
Customize settings for individual sObjects? (Y/n) (default: n): y
Override the global settings for object account
[account - count] Set number of records: 150
[account - language] Specify language: en
[account - fieldsToExclude] List fields (API names) to exclude: N/A
[account - fieldsToConsider] List fields (API names) to include: N/A
[account - pickLeftFields] Want to generate data for fields neither in 'fields toConsider' nor in 'fieldstoExclude': true
Override the global settings for another object (API name): y
Override the global settings for object lead
[lead - count] Set number of records: 50
[lead - language] Specify language: en
[lead - fieldsToExclude] List fields (API names) to exclude: N/A
[lead - fieldsToConsider] List fields (API names) to include: N/A
[lead - pickLeftFields] Want to generate data for fields neither in 'fieldsToConsider' nor in 'fieldsToExclude': true
Override the global settings for another object(default:n): n
Validate the added sObjects and their fields from your org (y/n) (default:n): n
Template Generated
{ "templateFileName": "account_leadTemplate_data_template.json", "namespaceToExclude": [], "outputFormat": ["di", "json"], "language": "en", "count": 200, "sObjects": [ { "account": { "count": 150, "language": "en", "pickLeftFields": true } }, { "lead": { "count": 50, "language": "en", "pickLeftFields": true } } ] }
Step 3: Now use the sf data generate command with the template name and alias/username: sf data generate -t account_leadTemplate_data_template.json -a alias/username.
📖Check out the Smock-It Use Case guide on GitHub for a better understanding of the scope of test data generation with Smock-It.
Best Practices to Create Test Data in Salesforce with Smock-It
Smock-It works best when you follow established best practices to get the finest data and test results. Follow these guidelines to maintain clean data, get full test coverage, streamline the development process, and make the most out of your test data generation:
Use Descriptive Field Values - Ensure data fields accurately reflect real-world scenarios.
Test Edge Cases - Generate data to cover both typical and edge-case scenarios.
Automate Test Data Refresh - Keep data updated with scheduled refreshes.
Validate Relationships - Maintain consistency between related Salesforce objects.
Conclusion
Smock-It tackles the daily challenges QA teams face in preparing test data to reduce time and effort, along with 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? Give it a try and save countless hours in Salesforce test data generation.
Let’s Talk!
Drop a note to move forward with the conversation!