PropicSignifi / Query.apex

A dynamic SOQL and SOSL query builder on Salesforce.com platform
https://propicsignifi.github.io/query-apex/
MIT License
153 stars 68 forks source link

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

Open sjurgis opened 2 years ago

sjurgis commented 2 years ago

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));
HenryRLee commented 2 years ago

Nice catch.

I think we need to get rid of the WITH SECURITY_ENFORCED phrase, if there is one, inside the lookup method.