TST_Mock.MockBuilder
Class
global inherited sharing class TST_Mock.MockBuilderFluent builder wrapper that delegates to TST_Builder.Builder for record construction and auto-registers built records with TST_Mock.
Methods
| Method | Description |
|---|---|
| global SObject build() | Builds a single mock record with a mock ID and registers it with TST_Mock for query interception. |
| global List<SObject> buildList() | Builds a list of mock records with mock IDs and registers them with TST_Mock for query interception. |
| global TST_Mock.MockBuilder withChildren(SObjectType childType, Integer count) | Adds child records to the parent mock without field overrides. |
| global TST_Mock.MockBuilder withChildren(SObjectType childType, Integer count, Map<SObjectField, Object> overrides) | Adds child records to the parent mock using SObjectField token overrides. |
| global TST_Mock.MockBuilder withChildren(SObjectType childType, Integer count, Map<String, Object> overrides) | Adds child records to the parent mock using String field name overrides. |
| global TST_Mock.MockBuilder withChildren(String relationshipName, TST_Builder.Builder childBuilder) | Adds child records using a pre-configured TST_Builder.Builder with an explicit relationship name. |
| global TST_Mock.MockBuilder withChildren(TST_Builder.Builder childBuilder) | Adds child records using a pre-configured TST_Builder.Builder with auto-detected relationship name. |
| global TST_Mock.MockBuilder withCount(Integer count) | Sets the number of mock records to build. |
| global TST_Mock.MockBuilder withCycle(SObjectField field, List<Object> values) | Assigns a list of values that cycle across mock records built by buildList(). |
| global TST_Mock.MockBuilder withCycle(String fieldName, List<Object> values) | Assigns a list of values that cycle across mock records built by buildList(). |
| global TST_Mock.MockBuilder withDefaultedField(SObjectField field) | Specifies a single field to populate with a default value using an SObjectField token. |
| global TST_Mock.MockBuilder withDefaultedField(String fieldName) | Specifies a single field to populate with a default value using a String name. |
| global TST_Mock.MockBuilder withDefaultedFields(List<Object> fields) | Specifies fields to populate with default values, even if not required. |
| global TST_Mock.MockBuilder withOptionalField(SObjectField field) | Specifies a field to treat as optional using an SObjectField token. |
| global TST_Mock.MockBuilder withOptionalField(String fieldName) | Specifies a field to treat as optional using a String name. |
| global TST_Mock.MockBuilder withOptionalFields(List<Object> fields) | Specifies fields to treat as optional, preventing auto-population. |
| global TST_Mock.MockBuilder withOverride(SObjectField field, Object value) | Sets a single field value override for the mock records. |
| global TST_Mock.MockBuilder withOverride(String fieldName, Object value) | Sets a single field value override using a String field name. |
| global TST_Mock.MockBuilder withOverrides(Map<SObjectField, Object> fieldOverrides) | Sets field value overrides for the mock records. |
| global TST_Mock.MockBuilder withOverrides(Map<String, Object> overrides) | Sets field value overrides using String field names. |
| global TST_Mock.MockBuilder withRecordType(String recordTypeDeveloperName) | Sets the Record Type for the mock records using the Record Type's DeveloperName. |
build
global SObject build()Builds a single mock record with a mock ID and registers it with TST_Mock for query interception.
Returns SObject — The built mock SObject record.
Example
Foobar__c mock = (Foobar__c)TST_Mock.of(Foobar__c.SObjectType).build();buildList
global List<SObject> buildList()Builds a list of mock records with mock IDs and registers them with TST_Mock for query interception.
Returns SObject — The list of built mock SObject records.
Example
List<SObject> mocks = TST_Mock.of(Foobar__c.SObjectType)
.withCount(3)
.buildList();withChildren
global TST_Mock.MockBuilder withChildren(SObjectType childType, Integer count)Adds child records to the parent mock without field overrides.
Parameters
| Parameter | Type | Description |
|---|---|---|
childType | SObjectType | The SObjectType of the child records. |
count | Integer | Number of child records to create. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
Account mock = (Account)TST_Mock.of(Account.SObjectType)
.withChildren(Contact.SObjectType, 3)
.build();global TST_Mock.MockBuilder withChildren(SObjectType childType, Integer count, Map<SObjectField, Object> overrides)Adds child records to the parent mock using SObjectField token overrides.
Parameters
| Parameter | Type | Description |
|---|---|---|
childType | SObjectType | The SObjectType of the child records. |
count | Integer | Number of child records to create. |
overrides | Map | Field overrides for child records using SObjectField tokens. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
Account mock = (Account)TST_Mock.of(Account.SObjectType)
.withChildren(Contact.SObjectType, 3, new Map<SObjectField, Object>{
Contact.LastName => 'Doe'
})
.build();global TST_Mock.MockBuilder withChildren(SObjectType childType, Integer count, Map<String, Object> overrides)Adds child records to the parent mock using String field name overrides.
Parameters
| Parameter | Type | Description |
|---|---|---|
childType | SObjectType | The SObjectType of the child records. |
count | Integer | Number of child records to create. |
overrides | Map | Field overrides for child records using String field names. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
Account mock = (Account)TST_Mock.of(Account.SObjectType)
.withChildren(Contact.SObjectType, 2, new Map<String, Object>{
'LastName' => 'Smith'
})
.build();global TST_Mock.MockBuilder withChildren(String relationshipName, TST_Builder.Builder childBuilder)Adds child records using a pre-configured TST_Builder.Builder with an explicit relationship name. Use when multiple relationships exist between the same parent and child types.
Parameters
| Parameter | Type | Description |
|---|---|---|
relationshipName | String | The child relationship name (e.g., 'Contacts'). |
childBuilder | TST_Builder.Builder | A pre-configured Builder instance for the child records. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
Foobar__c mock = (Foobar__c)TST_Mock.of(Foobar__c.SObjectType)
.withChildren('PrimaryContacts__r',
TST_Builder.of(Contact.SObjectType).withCount(2)
)
.build();global TST_Mock.MockBuilder withChildren(TST_Builder.Builder childBuilder)Adds child records using a pre-configured TST_Builder.Builder with auto-detected relationship name.
Parameters
| Parameter | Type | Description |
|---|---|---|
childBuilder | TST_Builder.Builder | A pre-configured Builder instance for the child records. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
Account mock = (Account)TST_Mock.of(Account.SObjectType)
.withChildren(
TST_Builder.of(Contact.SObjectType)
.withCount(2)
.withOverride(Contact.LastName, 'Doe')
)
.build();withCount
global TST_Mock.MockBuilder withCount(Integer count)Sets the number of mock records to build.
Parameters
| Parameter | Type | Description |
|---|---|---|
count | Integer | The number of records to create. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
List<SObject> mocks = TST_Mock.of(Foobar__c.SObjectType)
.withCount(5)
.buildList();withCycle
global TST_Mock.MockBuilder withCycle(SObjectField field, List<Object> values)Assigns a list of values that cycle across mock records built by buildList(). When more records are built than values provided, the values repeat from the beginning.
Parameters
| Parameter | Type | Description |
|---|---|---|
field | SObjectField | The SObjectField token of the field to cycle. |
values | List | The list of values to cycle through. Must not be null or empty. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
List<SObject> mocks = TST_Mock.of(Foobar__c.SObjectType)
.withCycle(Foobar__c.Picklist__c, new List<Object>{'Alpha', 'Beta', 'Gamma'})
.withCount(6)
.buildList();global TST_Mock.MockBuilder withCycle(String fieldName, List<Object> values)Assigns a list of values that cycle across mock records built by buildList(). When more records are built than values provided, the values repeat from the beginning.
Parameters
| Parameter | Type | Description |
|---|---|---|
fieldName | String | The API name of the field to cycle. |
values | List | The list of values to cycle through. Must not be null or empty. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
List<SObject> mocks = TST_Mock.of(Foobar__c.SObjectType)
.withCycle('Picklist__c', new List<Object>{'Alpha', 'Beta', 'Gamma'})
.withCount(6)
.buildList();withDefaultedField
global TST_Mock.MockBuilder withDefaultedField(SObjectField field)Specifies a single field to populate with a default value using an SObjectField token.
Parameters
| Parameter | Type | Description |
|---|---|---|
field | SObjectField | The SObjectField token of the field. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Account.SObjectType)
.withDefaultedField(Account.Description)
.build();global TST_Mock.MockBuilder withDefaultedField(String fieldName)Specifies a single field to populate with a default value using a String name.
Parameters
| Parameter | Type | Description |
|---|---|---|
fieldName | String | The API name of the field. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Foobar__c.SObjectType)
.withDefaultedField('Description')
.build();withDefaultedFields
global TST_Mock.MockBuilder withDefaultedFields(List<Object> fields)Specifies fields to populate with default values, even if not required.
Parameters
| Parameter | Type | Description |
|---|---|---|
fields | List | A list of fields (SObjectField tokens or String API names). |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Account.SObjectType)
.withDefaultedFields(new List<Object>{ 'Description', Account.Industry })
.build();withOptionalField
global TST_Mock.MockBuilder withOptionalField(SObjectField field)Specifies a field to treat as optional using an SObjectField token.
Parameters
| Parameter | Type | Description |
|---|---|---|
field | SObjectField | The SObjectField token of the field to mark as optional. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Account.SObjectType)
.withOptionalField(Account.Name)
.build();global TST_Mock.MockBuilder withOptionalField(String fieldName)Specifies a field to treat as optional using a String name.
Parameters
| Parameter | Type | Description |
|---|---|---|
fieldName | String | The API name of the field to mark as optional. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Account.SObjectType)
.withOptionalField('Name')
.build();withOptionalFields
global TST_Mock.MockBuilder withOptionalFields(List<Object> fields)Specifies fields to treat as optional, preventing auto-population.
Parameters
| Parameter | Type | Description |
|---|---|---|
fields | List | A list of fields (SObjectField tokens or String API names). |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Account.SObjectType)
.withOptionalFields(new List<Object>{ 'Name', Account.Type })
.build();withOverride
global TST_Mock.MockBuilder withOverride(SObjectField field, Object value)Sets a single field value override for the mock records.
Parameters
| Parameter | Type | Description |
|---|---|---|
field | SObjectField | The SObject field to override. |
value | Object | The value to set. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Foobar__c.SObjectType)
.withOverride(Foobar__c.Name, 'Test')
.build();global TST_Mock.MockBuilder withOverride(String fieldName, Object value)Sets a single field value override using a String field name. Supports relationship traversal paths like 'Account.Name'.
Parameters
| Parameter | Type | Description |
|---|---|---|
fieldName | String | The API name of the field. |
value | Object | The value to set. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Foobar__c.SObjectType)
.withOverride('Name', 'Test')
.build();withOverrides
global TST_Mock.MockBuilder withOverrides(Map<SObjectField, Object> fieldOverrides)Sets field value overrides for the mock records.
Parameters
| Parameter | Type | Description |
|---|---|---|
fieldOverrides | Map | Map of SObjectField to override values. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Foobar__c.SObjectType)
.withOverrides(new Map<SObjectField, Object>{ Foobar__c.Name => 'Test' })
.build();global TST_Mock.MockBuilder withOverrides(Map<String, Object> overrides)Sets field value overrides using String field names. Supports relationship traversal paths like 'Account.Name'.
Parameters
| Parameter | Type | Description |
|---|---|---|
overrides | Map | Map of field API names to override values. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Foobar__c.SObjectType)
.withOverrides(new Map<String, Object>{ 'Name' => 'Test', 'Account.Name' => 'Parent' })
.build();withRecordType
global TST_Mock.MockBuilder withRecordType(String recordTypeDeveloperName)Sets the Record Type for the mock records using the Record Type's DeveloperName.
Parameters
| Parameter | Type | Description |
|---|---|---|
recordTypeDeveloperName | String | The DeveloperName of the Record Type. |
Returns TST_Mock.MockBuilder — This MockBuilder instance for method chaining.
Example
TST_Mock.of(Account.SObjectType)
.withRecordType('Enterprise_Account')
.build();