Emulate a custom object’s “Recent Items” in a Visualforce page

How can I get a specific object’s ‘Recent Items’ object Ids in Apex or SOQL?
Please note. I am not talking about the recent Items displayed on the homepage showing object types.

I couldn’t find a way in Apex or the API to get the current user’s
recently viewed records of a SObject.

I want to render a “Recent Items” list on a custom Visualforce page
that looks exactly as shown when you click a tab.

enter image description here

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Building on Daniel Ballinger‘s answer to ‘How to get recent items’, the difference is really minor:

/services/data/v26.0/recent

gives you recent items like in the sidebar. “Object-specific” are well – object specific:

/services/data/v26.0/sobjects/Account
/services/data/v26.0/sobjects/Opportunity

etc.

enter image description here

Or raw output:

  "recentItems" : [ {
    "attributes" : {
      "type" : "Opportunity",
      "url" : "/services/data/v26.0/sobjects/Opportunity/0067000000AH3M7AAL"
    },
    "Id" : "0067000000AH3M7AAL",
    "Name" : "University of AZ Portable Generators111"
  }, {
    "attributes" : {
      "type" : "Opportunity",
      "url" : "/services/data/v26.0/sobjects/Opportunity/0067000000AH3M1AAL"
    },
    "Id" : "0067000000AH3M1AAL",
    "Name" : "Grand Hotels Kitchen Generator"
  }, {
    "attributes" : {
      "type" : "Opportunity",
      "url" : "/services/data/v26.0/sobjects/Opportunity/0067000000AH3MEAA1"
    }...

Method 2

There is a new object that will be available in Summer ’13 called RecentlyViewed that you can use in SOQL to get a user’s recently viewed records.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x