5

Salesforce REST APIs support endpoints for getting updated, deleted and recentlyviewed objects. I am interested in getting the recentlyviewed items. This endpoint returns data of the form

{ 
"attributes" : 
{ 
    "type" : "Account", 
    "url" : "/services/data/v28.0/sobjects/Account/a06U000000CelH0IAJ" 
}, 
"Id" : "a06U000000CelH0IAJ", 
"Name" : "Acme" 
}, 
{ 
"attributes" : 
{ 
    "type" : "Opportunity", 
    "url" : "/services/data/v28.0/sobjects/Opportunity/a06U000000CelGvIAJ" 
}, 
"Id" : "a06U000000CelGvIAJ", 
"Name" : "Acme - 600 Widgets"  
}

The problem is that this metadata does not contain information about the person who viewed this object. To understand the working of recentlyviewed I had to read up on how it is implemented. It seems that it is implemented using an SObject named RecentlyViewed . The explanation of this SObject says that itRepresents records that the **current user** has recently viewed or referenced.

The current_user would mean that it would only return the recentlyviewed objects of the user whose access token is being used to make the API call. So in order to get the recentlyviewed objects of all users i would have to make this API call with the access token of each and every user in the enterprise.

Here in lies my problem. I do not have the access tokens of all users in the company. I only have the access token of the enterprise admin. How do I go about getting the recentlyviewed items of all users? Does Salesforce offer some mechanism where the admin's access token can be used to impersonate API calls on behalf of other users? If not, is there any other way of solving this?

I am open to solutions using the SOAP API also.

1

You can not view recently viewed record of any other user except current. It is something like hacking into someone account without permission.

RecentlyViewed object only give access of current user records information. It is back-end copy of records shown on left side bar (Recent Items) when user open a record for any purpose.

There is no such field which can tell which user access that particular record. This limit applies to REST API also. https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_recentlyviewed.htm

| improve this answer | |
  • 1
    well 'something like hacking' is a perspective which not everyone might agree with. Most of the enterprise offerings out there provide a user-impersonation feature where the administrator can make calls on behalf of other users. Thats a key feature among many enterprise SaaS APIs e.g Box, Google Drive – auny Sep 24 '14 at 10:00
  • In that case you have to create a connected app and each user has to authorize that app so it can make call on their behalf. You can use refresh token to prevent frequent user authorizations. @auny – Ashwani Sep 24 '14 at 10:03
  • Thanks for the suggestion @regal but unfortunately that is not an option for me. Assume that there could be thousands of users in the enterprise, it is a pain to ask each one of them to go through this process. – auny Sep 24 '14 at 10:07
  • 1
    The answer is completely correct, assuming you stay inside of Salesforce. I would suggest something like Google Analytics where you can track pageviews against users and derive the records being viewed from the ID in the URI. – user735 Jan 15 '15 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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