+ Start a Discussion
:) :) :) :) :):) :) :) :) :) 

Last Accessed By field



We have Created By and Last Modified By fields by default but Is there any way in salesforce that we can create Last Accessed By using some sort of Session or custom APEX code.




You can use create one more field.

You can use either trigger or workflow to set that field.

You have to check whether lasmodifiedby standard field is  change or not .If change set your field.




:) :) :) :) :):) :) :) :) :)

I can't use Trigger because trigger only fires when any DML operation happens but here I am just looking the name of the uses who recently viewed this record. I might need to use recentlyviewd object to get that data.


SOQL Query for RecentlyViewed Items

Select Id, type, Alias, email, firstname, lastname, IsActive, LastReferencedDate, LastViewedDate, Name, phone, profileid, title, UserRoleID From RecentlyViewed




But I couldn't find the user id or user name who recently viewed this records




You can get the userid by doing soql in user object from the alias name.

But I am still not sure how the event will happen  to update the record.

Either you need to use batch apex or schedule class.