Loading

Salesforce SOQL Error: 'No Such Column LastViewedDate' on Custom Object (Custom Tab Required to Enable Field)

Publiseringsdato: Jun 8, 2026
Beskrivelse

Error Message

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.

Cause

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.

Løsning

Resolution Steps

To resolve the "No such column LastViewedDate" error on a custom object, create a custom tab for that object by following these steps:

  1. Navigate to Setup.
  2. In the Quick Find box, search for Tabs and click Tabs.
  3. Under Custom Object Tabs, click New.
  4. Select the custom object from the Object dropdown.
  5. Choose a Tab Style (icon) for the tab.
  6. Click Next, configure tab visibility as needed, and click Save.

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.

Knowledge-artikkelnummer

000382652

 
Laster
Salesforce Help | Article