function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Deepak PansariDeepak Pansari 

System.SObjectException: Field Lead.LastViewedDate is inaccessible [ LastViewedDate ]

Hi All,


I have a code which are getting all the fields name and their properties like api name, label , data type.


Now for deployed the code I am getting this exception :

System.SObjectException: Field Lead.LastViewedDate is inaccessible in this context.


It seems that there is a field "LastViewedDate" , I have checked all fields but I am not able to find this.

Please let me know if any one have any idea.





The target org you are deploying might have that field and some test method might be failing on that org.
Deepak PansariDeepak Pansari

Hi , 


I have checked again and there is no such field in any org.


Is there any way to find out what are the fields are present for Lead object.


- Deepak


Hi Deepak,

You can use the IDE (Eclipse) for Schema browsing. You can see all fields there or you can use Dynamic Apex also.

 For Dynamic Apex code snippets refer below article:

Deepak PansariDeepak Pansari

Hey Jitendra,


Thx I used the code mentined in the site , But still unable to find field "LastViewedDate".


Any other thoughts?


- Deepak


Hi Deepak,


If you are not able to see the field then it means it is not present. You will need to create that field.

Simply check them under leads fields
Deepak PansariDeepak Pansari



I have checked all possibe way to find that field in both org , but not able to find it.


If you see my subject line it seems "LastViewedDate" , its standard field.


- Deepak

When exactly you are getting this error ? While deploying ? If yes the there could be some more specific error message .
Laxman RaoLaxman Rao

Change the version of the class to 28.0.


LastViewedDate is accessible in summer 13.

You can refer here :

(search for LastViewedDate)

Pavlo Shchur 31Pavlo Shchur 31
Should version be 28 or it could be higer?
Shai FisherShai Fisher
It happen to me when i refreshed a VF page in lightning:
"Field Product2.LastViewedDate is inaccessible in this context".
When i refreshed the page by entering the page again (or entering the url again), and not by reloading, it solved.
This field is not referenced anywhere in my code.