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.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communitySOQL 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.
All Accounts that your user has access to:
SELECT Id, Name FROM Account
My Accounts
SELECT Id, Name FROM Account WHERE OwnerId = '<your user id>'
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.