Skip to content

SOQL Lib 6.1 toMap optimisations are incompatible with InnerJoin queries #315

Description

@packocz

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Query to find Permission Sets which contain a CustomPermission working in v5, breaks with v6.1. The last "AND ParentId != NULL" filter is added by the optimisation and is the culprit in this case.

SELECT Id FROM SetupEntityAccess WHERE (SetupEntityId IN (SELECT Id FROM CustomPermission WHERE (DeveloperName IN ('CustomPermissionName'))) AND Parent.IsOwnedByProfile = FALSE) AND ParentId != null

SOQL.of(SetupEntityAccess.SObjectType)
			.whereAre(
				SOQL.FilterGroup
					.add(
						SOQL.Filter.with(SetupEntityAccess.SetupEntityId)
							.isIn(
								SOQL.InnerJoin.of(CustomPermission.SObjectType)
									.with(CustomPermission.Id)
									.whereAre(
										SOQL.FilterGroup.add(SOQL.Filter.with(CustomPermission.DeveloperName).isIn(customPermissions))
									)
							)
					)
					.add(SOQL.Filter.with('Parent', PermissionSet.IsOwnedByProfile).isFalse()) 
			)
			.systemMode()
			.withoutSharing()
			.mockId(MOCK_ID_GET_PERM_SETS)
			.toMap(SetupEntityAccess.ParentId);

Expected behavior
Query should work, in some scenarios the key field used simply cannot be null. We should have an option to not "optimise". At least let's document a suitable workaround for these situations (not sure what it is yet - we are using toList for now and mapping in apex).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions