Skip to content
SObject factory that can be used in unit tests to create test data.
Apex
Branch: master
Clone or download
dhoechst Merge pull request #12 from MarkHMorrison/master
Add UserDefaults, Add Test.start()
Latest commit 5146c77 Jun 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
LICENSE.md Create LICENSE.md Mar 22, 2015
README.md Separated ObjectDefaults classes from test factory logic. Changed the… Jun 9, 2018

README.md

Salesforce-Test-Factory

SObject factory that can be used in unit tests to create test data.

Deploy to Salesforce

Usage:

// The TestFactory will pre-fill all the fields we typically need
Account a = (Account)TestFactory.createSObject(new Account());
insert a;

// You can also set values to be used. Any values set in the constructor will override the defaults
Opportunity o = (Opportunity)TestFactory.createSObject(new Opportunity(AccountId = a.Id));

// You can also specify a specific set of overrides for different scenarios
Account a = (Account)TestFactory.createSObject(new Account(), 'AccountDefaults');

// Finally, get a bunch of records for testing bulk
Account[] aList = (Account[])TestFactory.createSObjectList(new Account(), 200);

// You can optionally insert records as created like this:
// Note the final parameter of true.
Account a = (Account) TestFactory.createSObject(new Account(), true);
Contact c = (Contact) TestFactory.createSObject(new Contact(AccountID = a.Id), true);
You can’t perform that action at this time.