Print this page

Query on EntitySubscription

Knowledge Article Number 000181365
Description Scenario-
Some queries on EntitySubscription object do not execute for "Non-Admin" user and throw following exception :
MALFORMED_QUERY: Implementation restriction: EntitySubscription only allows security evaluation for non-admin users when LIMIT is specified and at most 1000
Resolution
The reason why some queries on EntitySubscription object does not execute for "Non-Admin" user and give following exception :
MALFORMED_QUERY: Implementation restriction: EntitySubscription only allows security evaluation for non-admin users when LIMIT is specified and at most 1000

is because there needs to be a limit of at most 1000 for EntitySubscription object for "Non-Admin" user and in the following query the limit was on account object.

WRONG QUERY SYNTAX :
SELECT Id, Name FROM Account WHERE Id IN (SELECT ParentId FROM EntitySubscription WHERE SubscriberId = '005A0000001vU2gIAE') LIMIT 1000

Now even if you try to run the query in following way :

SELECT Id, Name FROM Account WHERE Id IN (SELECT ParentId FROM EntitySubscription WHERE SubscriberId = '005A0000001vU2gIAE' LIMIT 1000)

it wont run as the LIMIT keyword cannot be used in sub query (LIMITATION from Salesforce) :
MALFORMED_QUERY:
SubscriberId = '005A0000001vU2gIAE' LIMIT 1000)
^
ERROR at Row:1:Column:124
expecting a right parentheses, found 'LIMIT


CORRECT QUERY SYNTAX
So this would be the ideal way of running the above query

SELECT ParentId, Parent.Name
FROM EntitySubscription
WHERE SubscriberId = '005A0000001vU2gIAE'
AND ParentId IN (
SELECT Id FROM Account
)
LIMIT 1000




promote demote