2

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

Thanks.

enter image description here

6

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.

| improve this answer | |
  • Thank Eduard, that's so helpful. – Justin TR Aug 3 '18 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.