This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @IsTest | |
| public class ParentWithNestedChildrenUtility { | |
| /** | |
| * @description Creates an in-memory SObject with nested related (child) records using JSON serialization and deserialization, without DMLs. | |
| * @param parentRecord The parent SObject record to receive children. | |
| * @param childrenRecords SObject records to be nested under the parent. | |
| * @param relationshipFieldName The relationship field name on Parent ('Contacts', 'Opportunities', 'Equipment_Maintenance_Items__r'). Using String, as "SObjectField" type cannot be used due to relationship fields on parent-side are not available that way. | |
| * @param populateFakeIds If true, fake Ids will be generated and assigned to parent and child records when their Ids are null. | |
| * @return The deserialized parent SObject with nested children records. |