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

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

Open
sjurgis opened this issue Jul 6, 2022 · 1 comment

Comments

@sjurgis
Copy link

sjurgis commented Jul 6, 2022

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
Copy link
Contributor

Nice catch.

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

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

2 participants