NebulaQueryAndSearch
NebulaQueryAndSearch copied to clipboard
addPolymorphicFields(SObjectField) uses hardcoded Who field when no mapping is specified even if the queried SObject does not contain such fields
System.debug(
new Query(Case.SObjectType)
.addPolymorphicFields(Case.OwnerId)
.getQuery()
);
result:
SELECT CaseNumber, Id, Who.Alias, Who.Email, Who.FirstName, (a lot of Who.X fields)
FROM Case
Obviously, such a query will fail. Result with getResults():
System.QueryException: Didn't understand relationship 'Who' in field path. (...)
The same happens if there is a Who relationship on the queried SObject, but we choose a different field, which is ignored:
System.debug(
new Query(Task.SObjectType)
.addPolymorphicFields(Task.WhatId)
.getQuery()
);
result:
SELECT Id, Subject, Who.Alias, Who.Email, Who.FirstName, (a lot of Who.X fields)
FROM Task
This query won't throw an exception, which is even worse, since is silently skips the field we expected to be queried.