When querying a Salesforce custom object using the LastReferencedDate or LastViewedDate fields in SOQL (Salesforce Object Query Language) — for example:
SELECT Id, LastViewedDate FROM MyCustomObject__c
— Salesforce returns the following error:
INVALID_FIELD: No such column 'LastViewedDate' on entity 'MyCustomObject__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name.
This error occurs even though LastViewedDate and LastReferencedDate are standard tracking fields available on most Salesforce objects.
The LastReferencedDate and LastViewedDate fields track when a record was last viewed or referenced by a user. However, these fields are stored as part of the object's tab definition in Salesforce. They do not physically exist for a custom object until a custom tab has been created for that object.
To resolve the "No such column LastViewedDate" error on a custom object, create a custom tab for that object by following these steps:
Once the custom tab is created and saved, re-run the SOQL query. The LastViewedDate and LastReferencedDate fields are now available on the custom object and the query returns results without error.
Note: The custom tab does not need to be visible to users in the navigation bar to enable these fields. Simply creating the tab is sufficient to activate the LastViewedDate and LastReferencedDate fields on the object.
000382652

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.