Mock sub select query (addQueryFactorySubselect
to ChildAccounts
)
#418
-
Is there a way to mock the response of this selector method with I feel like I'm missing some sort of mock for the // AccountSelector
public List<Account> selectById(Set<Id> idSet) {
if (idSet.isEmpty()) {
return new List<Account>();
}
fflib_QueryFactory qf = getQueryFactory();
qf.selectFields(getSObjectFieldListWithRelatedFields());
qf.setCondition('Id IN :idSet');
new AccountSelector().addQueryFactorySubselect(qf,'ChildAccounts');
return Database.query(qf.toSOQL());
} SObject recordthrows an error of Account accountRecord = new Account(
Id = fflib_IDGenerator.generate(Account.SObjectType),
ChildAccounts = new List<Account>{
new Account(
Id = fflib_IDGenerator.generate(Account.SObjectType),
Name = 'Child Account'
)
}
); SObject record (via
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @lukethacoder, I believe the serialization route is the better path to pursue. However, pull a native Account list having child Accounts from Salesforce, serialize and inspect. The ChildAccounts JSON property has some extra information to synthesize, including "totalSize", "done" and "records". The latter containing the serialized, children list. Here's a fairly simple, native serialization that I pulled:
|
Beta Was this translation helpful? Give feedback.
-
Also @lukethacoder, I was reminded by @ImJohnMDaniel that the fflib_ApexMocksUtils.makeRelationship(Type parentsType, List parents, SObjectField relationshipField, List<List> children) method that will do all of the work for you. |
Beta Was this translation helpful? Give feedback.
Hi @lukethacoder,
I believe the serialization route is the better path to pursue. However, pull a native Account list having child Accounts from Salesforce, serialize and inspect. The ChildAccounts JSON property has some extra information to synthesize, including "totalSize", "done" and "records". The latter containing the serialized, children list.
Here's a fairly simple, native serialization that I pulled: