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, Map<SObjectType, List<>>) with empty list in the map results in a malformed query #52

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

Comments

@TrangOul
Copy link

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
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