Skip to content

Data Generate Command

Sanyamj658 edited this page Jun 24, 2025 · 4 revisions

The generate command in the smock-it Salesforce plugin automates the generation of test data for Salesforce SObjects based on a user-defined template.

  • It supports generating data in multiple formats: JSON, CSV, and DI(direct insert) into Salesforce.
  • It also handles complex field types including picklists, references, and dependent picklists.
  • The command helps produce realistic datasets for development, testing, and QA environments.

How Does it Work?

  • Template Loading & Validation : Loads a template file (JSON) describing SObjects, fields, and data generation rules, and validates the configuration.
  • Salesforce Connection : Connects to the specified Salesforce org using the provided alias.
  • Field Configuration : Retrieves Salesforce metadata and prepares valid field values based on the template, handling picklists, references, and dependencies.
  • Data Generation : Uses the smockit-data-engine to generate synthetic data for each SObject and field, applying any special rules or value lists configured in the template.
  • Output Handling:
    • Outputs generated data as JSON, CSV, and DI (Data Insert) files into the data_gen/output/ directory.
    • If DI is selected, it inserts the generated records directly into Salesforce.
    • Logs results and errors, and summarizes the operation in a result table.

Using Generate command

Prerequisites

  • Properly formatted template JSON file.

Command Execution Format

sf smockit data generate -t <yourTemplate.json> -a <orgAliasorusername> 

Note: Parameters in square brackets [ ] are optional.

This command generates test data based on the specified template and inserts or outputs it using the connected Salesforce org alias.

Flag Supported

Flag Shorthand Required Description
--templateName -t Yes The name of the template JSON file to validate (with or without .json extension).
--aliasOrUsername -a Yes The Salesforce org alias or username to use for validation.
--sObject -s No (Optional) Name of a specific SObject to generate data
--excludeSObjects -z No (Optional) Name of a specific SObject to exclude for generating data from the given template
--recordType -r No (Optional) Name of a record type of SObject to generate data

Example :

Let's take an example where you have the contact.json template. This template defines the configurations for generating test data for the Contact object in Salesforce. Using the sf smockit data generate command, you can generate and insert test data based on the template’s specifications, including fields, record count, and any exclusions or predefined values.

Before executing the generate command - contact.json

{
  "namespaceToExclude": [],
  "outputFormat": [
    "json"
  ],
  "count": 4,
  "sObjects": [
    {
      "contact": {
        "count": 4,
        "fieldsToExclude": [
          "fax"
        ],
        "fieldsToConsider": {
          "firstname": []
        },
        "pickLeftFields": false
      }
    }
  ]
}

To generate test data using the contact.json template and connect to a Salesforce org using the alias or username test-oevhm9jkk3bx@example.com, run:

Executing data generate command

sf smockit data generate -t contact.json -a test-oevhm9jkk3bx@example.com

The generated output will appear in the data_gen/output/ folder in your chosen output formats.

After executing the command

[
  {
    "FirstName": "Anwar",
    "LastName": "Burton"
  },
  {
    "FirstName": "Donaciano",
    "LastName": "Dean"
  },
  {
    "FirstName": "Vennie",
    "LastName": "Cherry"
  },
  {
    "FirstName": "Casimir",
    "LastName": "Malone"
  }
]

📘 Read More

Clone this wiki locally