Skip to content

addPolymorphicFields(SObjectField) uses hardcoded Who field when no mapping is specified even if the queried SObject does not contain such fields #51

Description

@TrangOul
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions