fflib-apex-common
fflib-apex-common copied to clipboard
CurrencyIsoCode being added to subselect query on Who relationship for tasks
We have a Task Selector class and one of its methods builds up a subquery on the Who relationship. We noticed in multi currency orgs it is not only adding CurrencyIsoCode
to the task query but also adding Who.CurrencyIsoCode
. This causes it to throw an error since that fields does not exist.
Here's an example, I tried to trim it down as much as I could, so hopefully I didn't cut out anything important.
public with sharing class TasksSelector extends fflib_SObjectSelector {
public static TasksSelector newInstance() {
return (TasksSelector) Application.Selector.newInstance(Task.SObjectType);
}
public override String getOrderBy() {
return Task.WhatId.getDescribe().getName();
}
public List<Schema.SObjectField> getSObjectFieldList() {
return new List<Schema.SObjectField>{
Task.Id,
Task.OwnerId,
Task.Subject,
Task.ActivityDate,
Task.Status,
Task.WhatId,
Task.CreatedById,
Task.IsClosed
};
}
public Schema.SObjectType getSObjectType() {
return Task.sObjectType;
}
public List<Task> selectByWhatIdsWithOwnersAndContacts(
Set<Id> idSet
) {
fflib_QueryFactory taskQueryFactory = newQueryFactory();
ContactSelector.newInstance().configureQueryFactoryFields(taskQueryFactory, 'WhoId');
String whereClause = 'WhatId IN :idSet';
List<Task> result = new List<Task>();
result = Database.query(
taskQueryFactory
.selectField('Owner.Name')
.selectField('What.Name')
.setCondition(whereClause)
.addOrdering(Task.ActivityDate, fflib_QueryFactory.SortOrder.ASCENDING, true)
.addOrdering(Task.Subject, fflib_QueryFactory.SortOrder.ASCENDING, true)
.toSOQL()
);
return result;
}
}
@ImJohnMDaniel Since you and I regularly debate matters of pattern implementations, do you have observations about the general pattern existing here?
I'm getting a test failure upon running all tests after an initial deploy to our org:
fflib_QueryFactory.InvalidFieldException: Invalid field 'CurrencyIsoCode' for object 'Group'
Class.fflib_QueryFactory.getFieldPath: line 131, column 1 Class.fflib_QueryFactory.selectField: line 224, column 1 Class.fflib_SObjectSelector.configureQueryFactoryFields: line 388, column 1 Class.fflib_SObjectSelectorTest.testPolymorphicSelectWithRelatedType: line 486, column 1
It appears to be related to this issue, checking for CurrencyIsoCode
as a field on an Object where it doesn't exist. I thought I'd bump this thread back up and see if anyone else has experienced this.
@zkilburn86 -- thanks for reaching out. Is this error on an established codebase or is this brand new code/work?? If it is established, when did you first notice this issue?
Hi @ImJohnMDaniel thanks for the quick response! It is an existing code base, I did an initial deploy of the Apex Mocks and Apex Core master branches into a sandbox today, then ran the all tests to make sure everything checked out.
Ok. Let me check into it and see if I can replicate it
@zkilburn86 -- I have checked the codebase against the reference scratch org config that we use and nothing out of the ordinary is occurring. Is there any more information that you can provide that would help us reproduce the issue over here??
@ImJohnMDaniel sure thing, just to eliminate any conflicts with existing code I created a new scratch org and pushed only the Apex Mocks and Apex Core components.
Here's the project-scratch-def.json
I used to generate the org:
{ "orgName": "zkilburn company", "edition": "Developer", "features": ["EnableSetPasswordInApi"], "settings": { "lightningExperienceSettings": { "enableS1DesktopEnabled": true }, "mobileSettings": { "enableS1EncryptedStoragePref2": false } } }
I ran all tests in the org after push and they all passed as expected. Then I enabled multiple currencies from Setup > Company Information > Activate Multiple Currencies. I ran the tests again and got the failure from above Class.fflib_SObjectSelectorTest.testPolymorphicSelectWithRelatedType: line 486, column 1
- fflib_QueryFactory.InvalidFieldException: Invalid field 'CurrencyIsoCode' for object 'Group'