+ Start a Discussion
Bhawani SharmaBhawani Sharma 

Recent Records View

is there any way to get the recent viewed records on a visualforce page?

Best Answer chosen by Admin (Salesforce Developers) 
Bhawani SharmaBhawani Sharma

I got the work around for this.:smileyhappy:

All Answers

bob_buzzardbob_buzzard

Unfortunately not.  There is an idea to expose this via the API:

 

http://success.salesforce.com/ideaView?c=09a30000000D9xtAAC&id=08730000000BrkWAAS

 

but it doesn't have many votes and isn't marked under consideration.

 

If you scroll down the comments there's one from a 3rd party app exchange provider that might help.  

Ankit AroraAnkit Arora

Better if we promote the idea :)

I did.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Bhawani SharmaBhawani Sharma

I got the work around for this.:smileyhappy:

This was selected as the best answer
Ankit AroraAnkit Arora

It will be good if you share it :)

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

RupaliJRupaliJ

Hi,

Can you please provide the workarout to get the recently viewed records on visualforce page?

 

Thanks.

SayasoniSayasoni

Kindly share your work around.I desparately need something similar.

ctewellctewell

This will work for Leads. It gets content for a Salesforce page that shows most recent leads and extracts the Ids from there. These are then put in a list and used to query the Lead object.

 

This can be adapted for other objects by changing the lktp parameter to the prefix of the object you want to lookup and the lknm parameter from CampaignMember to an object name that has a lookup field to that object. You also have to change the findstring parameter.

 

public with sharing class ReferralsAndLeadsTabController {

    //public List<Lead> mruLeads{get;set;}
    public List<Lead> mruLeadList{get;set;}
    private void setMRULeads(){
        // Salesforce does not give us the most recent leads so this work around will suffice
        // We get the content of a Salesforce page that displays the Recent leads and then
        // extract the most recent ids from there.
       
        // This url is lookup page for field lookup up Lead object
        String url = '/00Q/o?nooverride=1';
        PageReference pageRef = new PageReference(url);
       
        String lookupContents = pageRef.getContent().toString();
        String findString = '\'00Q'; // Lead prefix
        integer leadIdIndex = lookupContents.indexOf(findString) + 1;
        List<Id> leadIdList = new List<Id>();
        String prevLeadId = '';
        while(leadIdIndex > 0){
            String leadId = lookupContents.substring(leadIdIndex, leadIdIndex + 15);
            if(leadId <> prevLeadId){
                leadIdList.add(leadId);
                prevLeadId = leadId;
            }
            leadIdIndex = lookupContents.indexOf(findString, leadIdIndex + 15) + 1;
        }
        system.debug('LeadIdList = ' + leadIdList);
        Map<Id, Lead> mruLeadMap = new Map<Id, Lead>([SELECT Id, Name, Company
                                                        FROM Lead
                                                        WHERE Id in :leadIdList]);
        // Now loop thru the ids and build the list with the leads in the correct order
        mruLeadList = new List<Lead>();
        integer seqnum = 0;
        for(Id leadId : leadIdList){
            mruLeadList.add(mruLeadMap.get(leadId));
        }                                                       
    }
    public ReferralsAndLeadsTabController(ApexPages.StandardSetController stdController) {
        setMRULeads();
    }
}

Bhawani SharmaBhawani Sharma

You need to introduce a piece on Javascript on your page. This Javascript will be derived from sidebar. Please let me know anyone is facing this issue and want me to post the solution.

SayasoniSayasoni
Please share the solution.
LVSLVS

Why not simply post the solution?

bob_buzzardbob_buzzard

Unfortunately some people want to take help from these boards but not contribute back.

colemabcolemab

Here is a link to an example using the REST API.  It would be nice to have this in native apex (vote for this idea).

 

That being said, I would love to see the javascript example . . .

bob_buzzardbob_buzzard

@Rocks1 that is using the web services API, LastViewedDate isn't available in Apex and hence Visualforce.

Thibault WeberThibault Weber

@bob_buzzard: Wrong, since summer 13, "LastViewedDate" and "LastReferencedDate" fields are now available on all objects in APEX. You also have the new "RecentlyViewed" object which represents records that the logged-in user has recently viewed or referenced.

 

http://www.salesforce.com/us/developer/docs/object_referencepre/Content/sforce_api_objects_recentlyviewed.htm