Skip to content

addPolymorphicFields(SObjectField, Map<SObjectType, List<>>) with empty list in the map results in a malformed query #52

Description

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

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