GitPedia

TestDataFactory

The ultimate Apex Test Data Factory ๐Ÿญ

From benahmยทUpdated April 1, 2026ยทView on GitHubยท

Generate & insert an sObject with all the required fields & relationships auto-filled ```apex Contact con = (Contact)TestDataFactory.createSObject('Contact'); ``` The project is written primarily in Apex, distributed under the Apache License 2.0 license, first published in 2017. Key topics include: apex, data-factory, salesforce.

Latest release: V3.2
August 30, 2021View Changelog โ†’

Apex Test Data Factory

<p align="center"><img src ="./documentation/assets/logo.png" width="400"/></p>

โ€œ The ultimate Apex Test Data Factory โ€ :factory: :ok_hand:

Generate & insert an sObject with all the required fields & relationships auto-filled

apex
Contact con = (Contact)TestDataFactory.createSObject('Contact');

Inserted data*:

javascript
Contact:{Id='0036E00000R4nG0QAJ', Lastname:'test0'}
<br/>

Assign values to fields of the main sObject and the related sObjects

apex
Contact con = (Contact)TestDataFactory.createSObject('Contact', new Map<String,Object>{ 'Email' => 'test@email.com', 'Account.Description' => 'Text for the Description field on the Account' });

Inserted data*:

apex
Contact:{Id='0036E00000R55chQAB', Lastname:'test0', Email:'test@email.com', AccountId='0016E00000Z6bC7QAJ'} Account:{Id='0016E00000Z6bC7QAJ', Name='test0', Description='Text for the Description field on the Account'}
<br/>

* in a non-customized org

Install :

Get the TestDataFactory class by installing the TestDataFactory Unlocked Package ๐Ÿ”“๐Ÿ“ฆ in your org using the UI or by running the following sfdx command

sfdx force:package:install --wait 10 --publishwait 10 --package 04t1n000002WsK5AAK -r -u AliasOfYourOrg

More :

Releases ๐Ÿ“ฆ

License ๐Ÿ”ฐ

Apache 2.0

Contributors

Showing top 3 contributors by commit count.

View all contributors on GitHub โ†’

This article is auto-generated from benahm/TestDataFactory via the GitHub API.Last fetched: 6/14/2026