Skip to main content
[ This file is autogenerated from apexdoc ]

AqApexMocksUtils

Group modules/enterprise

Methods​

public static Object makeRelationship(Type parentsType, List<SObject> parents, SObjectField relationshipField, List<List<SObject>> children)​

This is taken from https://gist.github.com/afawcett/8dbfc0e1d8c43c982881. This method works on the principle that serializing and deserialising child records is supported apex System.assertEquals(1, ((List&lt;Master__c&gt;) JSON.deserialize( JSON.serialize( [select Id, Name, (select Id, Name from Children__r) from Master__c]), List&lt;Master__c&gt;.class)) [0].Children__r.size()); This method results internally in constructing this JSON, before deserialising it back into SObject's

Example​

[
{
"attributes": {
"type": "Master__c",
"url": "/services/data/v32.0/sobjects/Master__c/a0YG0000005Jn5uMAC"
},
"Name": "Fred",
"Id": "a0YG0000005Jn5uMAC",
"Children__r": {
"totalSize": 1,
"done": true,
"records": [
{
"attributes": {
"type": "Child__c",
"url": "/services/data/v32.0/sobjects/Child__c/a0ZG0000006JGPAMA4"
},
"Name": "Bob",
"Id": "a0ZG0000006JGPAMA4",
"Master__c": "a0YG0000005Jn5uMAC"
}
]
}
]

public static Object makeRelationship(String parentTypeName, String childTypeName, List<SObject> parents, String relationshipFieldName, List<List<SObject>> children)​

Generic overload to makeRelationship. Enables creation of relationships in a loosely-coupled manner.

public static Object setReadOnlyFields(SObject objInstance, Type deserializeType, Map<SObjectField,Object> properties)​

Gives the ability to set test values on formula and other read-only fields of mock SObjects