Method | Supported signatures |
---|---|
createSObject |
* createSObject(String sObjectName) // create an sObject with all required fields auto-filled and insert all sObjects
* createSObject(String sObjectName,Boolean doInsert) // create an sObject with all required fields auto-filled and insert all sObjects if the doInsert = true
* createSObject(String sObjectName, Map<String,Object> mapValuesOverride) // create an sObject with all required fields auto-filled, assign the values defined in the mapValuesOverride and insert all sObjects if the doInsert = true
* createSObject(String sObjectName, Map<String,Object> mapValuesOverride, Boolean doInsert) // create an sObject with all required fields auto-filled, assign the values defined in the mapValuesOverride and insert all sObjects if the doInsert = true |
createSObjectList |
* createSObjectList(String sObjectName, Integer numberOfSObjects) // create a list of sObject with all required fields auto-filled and insert all sObjects
* createSObjectList(String sObjectName, Integer numberOfSObjects, Boolean doInsert) // create a list of sObject with all required fields auto-filled and insert all sObjects if the doInsert = true
* createSObjectList(String sObjectName, Map<String,Object> mapValuesOverride, Integer numberOfSObjects) // create a list of sObject with all required fields auto-filled, assign the values defined in the mapValuesOverride and insert all sObjects
* createSObjectList(String sObjectName, Map<String,Object> mapValuesOverride, Integer numberOfSObjects, Boolean doInsert) // create a list of sObject with all required fields auto-filled, assign the values defined in the mapValuesOverride and insert all sObjects if the doInsert = true |
Contact con = (Contact)TDF.createSObject('Contact');
You can assign values to the main sObject or any related sObject, all sObjects will be created with the required fields auto-filled
Contact con = (Contact)TDF.createSObject('Contact', new Map<String,Object>{
'FirstName' => 'Doe',
'LastName' => 'John',
'Account.Description' => 'Description of the related account',
'Account.Parent.Name' => 'Name of the parent Account'
});
You can auto-generate a value for a non required field by assigning the TDF.DEFAULT_VALUE to it, in the Map of values
Contact con = (Contact)TDF.createSObject('Contact', new Map<String,Object>{
'Description' => TDF.DEFAULT_VALUE,
'Account.Phone' => TDF.DEFAULT_VALUE
});
For example when creating a Contact you can force the Test Data Factory to create a related Account, even if an Account is not required
Contact con = (Contact)TDF.createSObject('Contact', new Map<String,Object>{
'AccountId' => TDF.DEFAULT_VALUE
});
You can provide a sub map of values for a related sObject
Contact con = (Contact)TDF.createSObject('Contact', new Map<String,Object>{
'Description' => 'Contact description',
'Account' => new Map<String,Object>{
'Name' => 'Account Name',
'Description' => 'Account Description'
}
});
You can provide an Id for a required related sObject, to force the use of that Id and prevent the instantiation of the related sObject
User u = (User)TDF.createSObject('User', new Map<String,Object>{
'ProfileId' => UserInfo.getProfileId()
});
Create & insert 10 contact sObject instances
List<Contact> conList = TDF.createSObjectList('Contact',true,10);
The following code creates 10 users with different usernames and nicknames
List<User> uList = TDF.createSObjectList('User', new Map<String,Object>{
'ProfileId' => UserInfo.getProfileId(),
'Username' => 'test{!index}@mytestdomain.developer',
'CommunityNickname' => 'test{!index}'
},10);
Create a list of 5 Account sObjects with different names and a same description
List<Account> accList = TDF.createSObjectList('Account', new Map<String,Object>{
'Name' => new List<String>{'Alex','Jack','Susie','Sarah','Paul'}
'Description' => 'Same description'
},5);
Create a list of Acount sObjects and link them to a list of 10 Case sObjects
List<Account> accList = TDF.createSObjectList('Account', new Map<String,Object>{
'Description' => 'Account Description'
},10);
List<Case> caseList = TDF.createSObjectList('Case', new Map<String,Object>{
'Account' => AccList,
'Contact.Account' => AccList
},10);