What does this implement/fix? Explain your changes.
When trying to mock a SObject with parent record fields from a polymorphic relationship, i can't set these using fflib_ApexMocksUtils.setReadOnlyFields()
Example query i want to mock:
SELECT Id, Subject, TYPEOF What WHEN Account THEN Id, Name END FROM Task
Trying this:
Account acc = new Account(Name='TestAccount');
Task t = new Task(
What = acc
);
results in: Field is not writeable: Task.What
fflib_ApexMocksUtils.setReadOnlyFields() only allows to set readonly fields using a Map<SObjectField, Object>, which does not help in this case.
So this PR adds a new overload setReadOnlyFields(SObject objInstance, Type deserializeType, Map<String, Object> properties), which allows me to do this, using strings instead of SObjectField:
Task t = (Task)fflib_ApexMocksUtils.setReadOnlyFields(
new Task(Subject='TestTask'),
Task.class,
new Map<String, Object> {'What' => acc}
);
What does this implement/fix? Explain your changes.
When trying to mock a SObject with parent record fields from a polymorphic relationship, i can't set these using
fflib_ApexMocksUtils.setReadOnlyFields()
Example query i want to mock:
Trying this:
results in:
Field is not writeable: Task.What
fflib_ApexMocksUtils.setReadOnlyFields()
only allows to set readonly fields using aMap<SObjectField, Object>
, which does not help in this case.So this PR adds a new overload
setReadOnlyFields(SObject objInstance, Type deserializeType, Map<String, Object> properties)
, which allows me to do this, using strings instead of SObjectField:This change is