Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TrangOul opened this issue Aug 12, 2024 · 0 comments

Comments

@TrangOul
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant