You need to sign in to do that
Don't have an account?
Recent Records View
is there any way to get the recent viewed records on a visualforce page?
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
is there any way to get the recent viewed records on a visualforce page?
I got the work around for this.:smileyhappy:
All Answers
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.
Better if we promote the idea :)
I did.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
I got the work around for this.:smileyhappy:
It will be good if you share it :)
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Hi,
Can you please provide the workarout to get the recently viewed records on visualforce page?
Thanks.
Kindly share your work around.I desparately need something similar.
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();
}
}
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.
Why not simply post the solution?
Unfortunately some people want to take help from these boards but not contribute back.
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 . . .
Please go through the following link:
http://www.salesforce.com/us/developer/docs/object_referencepre/Content/sforce_api_objects_recentlyviewed.htm
@Rocks1 that is using the web services API, LastViewedDate isn't available in Apex and hence Visualforce.
@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