You need to sign in to do that
Don't have an account?
Rocks_SFDC
How to Fetch the Recently Viewed Accounts through SOQL Query by using Apex
Hello Everyone,
Could anyone please let me know how we can write the SOQL Query to fetch the recently viewed Accounts.
Thanks in Advance,
Anil
<apex:page controller="recentlyviewrecords">.
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!acc}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.LastViewedDate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
public class recentlyviewrecords {
public list<account> acc{set;get;}
public recentlyviewrecords()
{
acc=[SELECT Id, Name,LastViewedDate FROM account WHERE LastViewedDate !=null ORDER BY LastViewedDate DESC limit 10];
}
}
All Answers
<apex:page controller="recentlyviewrecords">.
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!acc}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.LastViewedDate}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
public class recentlyviewrecords {
public list<account> acc{set;get;}
public recentlyviewrecords()
{
acc=[SELECT Id, Name,LastViewedDate FROM account WHERE LastViewedDate !=null ORDER BY LastViewedDate DESC limit 10];
}
}
Yeah..Just now i got this.......anyways thanks very much !!!!!!
Hi,
You can use the "LastViewedDate" field of any Sobject to view the recently viewed record.
As:
List<Account> accList = [SELECT Account.Name FROM Account WHERE LastViewedDate != NULL ORDER BY LastViewedDate DESC];
You can use "ORDER BY LastViewedDate DESC" in your query.
Please go through the below URL:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_recentlyviewed.htm
If this post helps you please give Kudos.
Actually, the best way to do this is to use the MRU token in the SOQL query:
List<Account> accList = [SELECT Account.Name FROM Account MRU LIMIT 5];