-
Notifications
You must be signed in to change notification settings - Fork 10
Template Validate Command
The validate command in the smock-it Salesforce plugin validates a data template JSON file before data generation. It checks that all referenced Salesforce objects (SObjects) and fields exist and are accessible in the target Salesforce org, preventing misconfigurations and runtime errors for a smoother process.
- Reads the Template: The command loads a specified JSON template file containing SObject and field configurations.
- Connects to Salesforce: It establishes a connection to the Salesforce org using a provided user alias.
- Validates SObjects: Checks if all SObjects listed in the template exist in the org.
- Validates Fields: For each SObject, it verifies that all specified fields (including those to consider or exclude) exist and are accessible.
- Checks for Conflicts: Ensures that the same field is not present in both fieldsToConsider and fieldsToExclude.
- Reports Issues: Warns or errors out if any SObjects or fields are invalid, missing, or misconfigured.
- Success Message: If everything is valid, it confirms successful validation.
Prerequisites
- Valid Salesforce org and user alias.
- Properly formatted template JSON file.
Command Execution Format
sf smockit template validate -t <yourTemplate.json> -a <orgAliasorusername>| Flag | Shorthand | Required | Description |
|---|---|---|---|
| -- templateName | -t | Yes | The name of the template JSON file to validate (with or without .json extension). |
| -- alias or Username | -a | Yes | The Salesforce org alias or username to use for validation. |
To demonstrate how Smock-It validates templates and detects configuration issues, the following example uses an intentionally misconfigured template. This helps illustrate how Smock-It identifies errors related to dependent picklists, invalid fields, and incorrect object relationships.
Before executing the validate command - invalid_account.json
{
"namespaceToExclude": [],
"outputFormat": [
"di",
"json"
],
"count": 1,
"sObjects": [
{
"Account": {
"count": 1,
"fieldsToConsider": {
"State__c": [
"India"
]
},
"fieldsToExclude": [
"Country__c"
],
"pickLeftFields": true,
"relatedSObjects": [
{
"Contact": {
"count": 1,
"fieldsToConsider": {
"InvalidField__c": []
},
"fieldsToExclude": [],
"pickLeftFields": true
}
},
{
"Lead": {
"count": 1,
"fieldsToConsider": {},
"fieldsToExclude": [],
"pickLeftFields": true
}
}
]
}
}
]
}
Executing validate command
sf smockit template validate -t invalid_account.json -a test-z1z3nrh9wmws@example.comValidation Output (Negative Scenario)
Smock-It reports the following issues during validation:
CRITICAL LOGIC/STRUCTURAL ERRORS FOUND:
• Account:
- Warning: Dependent field 'State__c' requires controller 'Country__c',
but 'Country__c' is listed in fieldsToExclude.
Invalid fields found (Typos / Missing Fields):
• Account -> Contact: InvalidField__c
Invalid relationships found:
• Invalid relationship: Account -> Lead
Error:
Validation completed with errors or warnings above.
Explanation of Detected Issues
-
Dependent Picklist Validation:
State__cis a dependent picklist field that requires the controller fieldCountry__c. SinceCountry__cis excluded, Smock-It flags this as a validation warning. -
Invalid Field Detection: The field
InvalidField__cdoes not exist on the Contact object, and Smock-It detects it as an invalid field. -
Dependent Picklist Validation:
Leadis not a valid child relationship ofAccount. Smock-It validates object relationships and reports this as an error.
This example demonstrates how the validate command proactively detects structural and logical issues, helping prevent runtime failures during data generation.
© 2025 Concret.io, All Rights Reserved. | For a quick demo and guided installation: Schedule a Call. | Smock-it Website