Skip to content

Using enforceGlobalSecurity and lookup() throws System.QueryException: expecting an equals sign, found ')' #83

@sjurgis

Description

@sjurgis

Consider example:

Query.enforceGlobalSecurity();
Query q = new Query(Account.SObjectType)
        .selectFields(new String[]{'Name'})
        .lookup('Id',
                new Query(Contact.SObjectType)
                        .selectField(Contact.AccountId));
System.debug(q.toQueryString());
q.run();

Which creates query

SELECT name FROM Account WHERE (Id IN (SELECT accountid FROM Contact WITH SECURITY_ENFORCED)) WITH SECURITY_ENFORCED

The problem is with inner join query has WITH SECURITY_ENFORCED which fails SOQL parser.

As a workaround you can disable security check for lookup query:

Query q = new Query(Account.SObjectType)
        .selectFields(new String[]{'Name'})
        .lookup('Id',
                new Query(Contact.SObjectType)
                        .enforceSecurity(false)
                        .selectField(Contact.AccountId));
                       

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions