NebulaQueryAndSearch
NebulaQueryAndSearch copied to clipboard
addPolymorphicFields(SObjectField, Map<SObjectType, List<>>) with empty list in the map results in a malformed query
System.debug(
new Query(Task.SObjectType)
.addPolymorphicFields(
Task.WhoId,
new Map<SObjectType, List<SOQL.QueryField>>{
Contact.SObjectType => new List<SOQL.QueryField>{}
}
)
.getQuery()
);
When addPolymorphicFields(SObjectField, Map<SObjectType, List<SObjectField>>)
or addPolymorphicFields(SObjectField, Map<SObjectType, List<SOQL.QueryField>>)
is used with a non-empty map, but with empty list as one of the values, the resulting query literally queries no fields for that SObject type (notice the double space after THEN
):
SELECT Id, Subject, TYPEOF Who WHEN Contact THEN ELSE Alias, Email, (...) END FROM Task
Please consider throwing a runtime exception for an empty list or, arguably better, adding Id
as the default field if none are specified:
SELECT Id, Subject, TYPEOF Who WHEN Contact THEN Id ELSE Alias, Email, (...) END FROM Task