I want to query data of Account with a standard filter likes (All, All Accounts, My Accounts,..).

How can I apply one of these filters to SOQL query below?

SELECT Id, Name FROM Account ORDER BY lastmodifiedDate DESC


enter image description here

1 Answer 1


SOQL does not allow using filter literals like (All, All Accounts, My Accounts,..) directly.

You can achieve that by using standard fields on the Account object.

  1. All Accounts that your user has access to:

    SELECT Id, Name FROM Account

  2. My Accounts

    SELECT Id, Name FROM Account WHERE OwnerId = '<your user id>'

  3. Recently Viewed

    SELECT Id, Name FROM Account WHERE LastViewedDate !=null ORDER BY LastViewedDate LIMIT 10

While the queries above return all records that satisfy the WHERE condition, bear in mind that you might not see absolutely all accounts if your Sharing Settings is Private for Accounts. In apex classes you might regulate that behavior by using with sharing or without sharing keywords. On the other hand executing SOQL in the Developer Console either from Anonymous or Query Editor will respect full permissions of the current user.

The only exceptions to this rule are Apex code that is executed with the executeAnonymous call and Chatter in Apex. executeAnonymous always executes using the full permissions of the current user.

  • Thank Eduard, that's so helpful.
    – Justin TR
    Commented Aug 3, 2018 at 2:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .