There is already excellent snowfakery documenation. This one-pager acts as a quick-reference guide for common scenarios when working with Salesforce objects ans associated field types.
- Python 3
- Snowfakery
- Download the latest version of python here: https://www.python.org/downloads/
- Be sure to select "Add to PATH" when prompted in the install/setup window
- After installing we will need to restart our machine
- Confirm successful install by opening up a terminal and typing "python --version"
for more info and documentation on Python: https://www.python.org/
- With python installed we can enter in a terminal "pip install snowfakery"
- Confirm successful install by typing in the terminal "snowfakery --version"
- Snowfakery Central Concepts
- Index of Fake Data Types
- Snowfakery "Friends" - For every object Contact I create...
- Snowfakery "Relationships"
- Snowfakery "date_between"
In order for the snowfakery recipe to work as expected it must be in the correct YAML Syntax
- Reference Map for Salesforce Faker Values by Field Type
- Salesforce Field Type based Snowfakery Fake Value Examples
- Scenario and Criteria based Snowfakery Fake Value Examples
- Using Variable Syntax to Reference Already Existing Record in Recipe
- Generating Fake Date Values that fit within Start and End Date Fields
- SET MAXIMUM, MINIMUM, AND RANGE OF CHARACTERS: Use different String and Text Faker Providers to set minimum, maximum and a range of allotted text characters
- How to fake number values with only whole-numbers using "random_number" faker provider
- Snowfakery Documentation References
checkbox : ${{ random_choice("true","false") }} }
currency : ${{ fake.pyfloat( right_digits = 2, positive=True, min_value=None, max_value=1000000) }}
date : ${{ fake.date}}
datetime : ${{ fake.date}}
email : ${{ fake.ascii_safe_email}}
number : ${{ fake.pyint( min_value = -10000, max_value = 100000 ) }}
percent : ${{ fake.pyint( min_value = 0, max_value = 100) }}
picklist : ${{ random_choice("alpha","bravo","charlie","delta","foxtrot") }}
phone : ${{ fake.phone_number }}
multiselectpicklist : ${{ ";".join(( fake.random_sample( elements=("alpha","bravo","charlie","delta","echo","foxtrot" ) ) )) }}
text : ${{ fake.text(max_nb_chars=20) }}
html : ${{ fake.sentence }}
textarea : ${{ fake.paragraph }}
time : ${{ fake.time }}
longtextarea : ${{ fake.paragraph }}
url : ${{ fake.url }}
encryptedtext : ${{ fake.credit_card_number }}
A location type field will require a latitude and longitude value as it is a:
"Compound Field" - https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/compound_fields_geolocation.htm.
To satisfy this compound field syntax within a snowfakery recipe we will provide a latitude and longitude.
For example, if the field's api name was "geolocation__c"
geolocation__latitude__s:
fake: latitude
geolocation__longitude__s:
fake: longitude
The "...." is filler for where other fields would usually be.
- object: ParentRecord__c
nickname: ParentRecord__c_NickName
count: 1
fields:
....
- object: ChildRecord__c
count: 5
fields:
MyParentLookupField__c:
reference: ParentRecord__c_NickName
....
To fake a picklist use the below syntax that encompasses possible picklist values for the field:
picklist1__c:
random_choice:
- 'bravo'
- 'alpha'
- 'charlie'
- 'delta'
- 'echo'
- 'foxtrot'
In faking data for a picklist and associated dependent picklist we can leverage the below syntax.
In the example below the field picklist1__c is the referenced parent picklist for the dependent picklist dependentpicklist1__c.
Depending on the value for picklist1__c, the available choices for dependentpicklist__c will be limited based on the random choice set in the picklist1__c field.
picklist1__c:
random_choice:
- 'bravo'
- 'alpha'
- 'charlie'
- 'delta'
- 'echo'
- 'foxtrot'
dependentpicklist1__c:
if:
- choice:
when: ${{picklist1__c=='alpha'}}
pick:
random_choice:
- sierra
- choice:
when: ${{picklist1__c=='bravo'}}
pick:
random_choice:
- sierra
- tango
- choice:
when: ${{picklist1__c=='charlie'}}
pick:
random_choice:
- sierra
- tango
- uniform
- victor
- choice:
when: ${{picklist1__c=='delta'}}
pick:
random_choice:
- sierra
- tango
- uniform
- victor
- choice:
when: ${{picklist1__c=='echo'}}
pick:
random_choice:
- sierra
- tango
- choice:
when: ${{picklist1__c=='foxtrot'}}
pick:
random_choice:
- sierra
DEPENDING ON WHAT APPROACH IS USED TO INSERT THE GENERATED DATA RECIPES, THE PARENT PICKLIST (picklist1__c) MUST BE LISTED IN THE YAML BEFORE THE DEPENDENT PICKLIST OR THERE WILL BE NO PARENT PICKLIST VALUE GENERATED FOR THE DEPENDENT PICKLIST TO USE AS ITS BEING PROCESSED BY SNOWFAKERY
In the below example we are referencing 3 already existing User Id's in an object recipe (This is not a healthy object relationship practice but is common in salesforce). These User Id's are then set as the variable values for lookups in an object recipe. That object recipe will generate a mix of fake values and hard-set values based on the variables provided in the recipe:
- related_user variable set for Related_User__c field
- site_supervisor variable set for Site_Supervisor__c field
- team_leader_user_record variable set for Team_Leader__c field
- var: team_leader_user_record
value: 0053R000002A0IiQAK
- var: site_supervisor
value: 0053R000002A0IiJON
- var: related_user
value: 0053R000002A0IiHEY
- object: Poorly_Setup_Object_Relationships__c
count: 1
nickname: Poorly_Setup_Object_Relationships__c_NickName
fields:
OtherField__c: ${{ fake.text(max_nb_chars=40) }}
Related_User__c: ${{ related_user}}
Site_Supervisor__c: ${{ site_supervisor }}
Team_Leader__c: ${{ team_leader_user_record }}
Using a combination of fake values and variable references, we can set the range criteria for an initial start date and use that generated start date to provide the start-range-criteria for a randomly generated end date:
Start_Date__c:
date_between:
start_date: -10d
end_date: +15d
End_Date__c:
date_between:
start_date: ${{ Start_Date__c}}
end_date: +50d
SET MAXIMUM, MINIMUM, AND RANGE OF CHARACTERS: Use different String and Text Faker Providers to set minimum, maximum and a range of allotted text characters
To cap the maximum and minimum amount of characters to be faked for a text field it will depend on the type of fake value we want.
If we want random characters we can set ranges for both minimum and maximum amount of characters:
- object: Account
count: 1
nickname: Account_RandomRange_Test
fields:
Name: ${{ fake.pystr( max_chars = 15, min_chars = 10 ) }}
RESULT:
Account(id=1, Name=pZZUvOLZdLGYGzk)
If we want somewhat realistic text(human language), we have only been able to find a way to set the maximum amount. There could be a way to set minimum but we haven't found it yet. To set the maximum characters for the "text" fake provider, use the argument "max_nb_chars":
- object: Account
count: 1
nickname: Account_Max_Test
fields:
Name: ${{ fake.text( max_nb_chars = 15 ) }}
RESULT:
Account(id=1, Name=Story catch.)
There are several integer/number fake providers within the "Faker" library used under-the-hood by Snowfakery. Use the below fake number syntax to ensure a whole number:
Number_Field_With_No_Decimal_Places__c: ${{ fake.random_number }
If we want to generate whole number within a specific range we can use the below syntax:
- object: Account
count: 1
nickname: Account_Number_Between_Range
fields:
Number_Field__c: ${{random_number(min=5, max=10)}}
RESULT:
Account(id=1, Number_Field__c=8)