Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question
2  
Since I can't see a way to move an answer to the original question, I'm editing this one to remove the 'shouting' and deleting the original closed question. Seems like an honest mistake. –  metadaddy Dec 10 '12 at 17:53
add comment

2 Answers

up vote 4 down vote accepted

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"
    }...
share|improve this answer
    
Thanks for pointing me to the fact that the REST API also offers Recent Items for objects. –  Robert Sösemann Dec 10 '12 at 12:37
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.