0

I have visualforce page that not using standardController.I would like to include the standard Recent Items inside my page.

I read on question here ,but I can get Name ,Id etc but how can I have the link,icon same like the standard Recent Items ?

***********Updated************

Basically, I want to copy the RecentItem in SFDC Homepage to my own visualforce Homepage.

This is view from SFDC Homepage.

enter image description here

I can get the same Id and Name from RecentlyViewed object using SOQL below

 RecentItem  =[SELECT Id, Name  FROM RecentlyViewed ORDER BY LastViewedDate DESC LIMIT 10];

But I don't know how to get URL and icon similar with Home RecentItem.I tried with this code, but still I cannot get 'Home' applabel and relate it with RecentlyViewed in query above.

//This already give us the details of Id and Name in RecentItem but not URL and icon.
RecentlyViewed[] recents = [
        SELECT Id, Name
        FROM RecentlyViewed
        ORDER BY LastViewedDate DESC
        LIMIT 10
        ];
Set<String> types = new Set<String>();
for (RecentlyViewed r : recents) {
    types.add(String.valueOf(r.Id.getSObjectType()));
    system.debug('@Checking ---'+String.valueOf(r.Id.getSObjectType()));
}

List<Schema.DescribeTabSetResult> tabSetDesc = Schema.describeTabs();
for(DescribeTabSetResult tsr : tabSetDesc) {
    String appLabel = tsr.getLabel();
      System.debug('@Checking --appLabel '+appLabel);
    //No home label available,if it available how to get url of RecentlyViewed item and its icon.
    if(appLabel=='Home'){
        List<Schema.DescribeTabResult> tabDesc = tsr.getTabs();
        System.debug('-- Tab information for the Sales app --');
        for(Schema.DescribeTabResult tr : tabDesc) {
            System.debug('@Checking getLabel: ' + tr.getLabel());
            System.debug('@Checking getColors: ' + tr.getColors());
            System.debug('@Checking getIconUrl: ' + tr.getIconUrl());
            System.debug('@Checking getIcons: ' + tr.getIcons());
            System.debug('@Checking getMiniIconUrl: ' + tr.getMiniIconUrl());
            System.debug('@Checking getSobjectName: ' + tr.getSobjectName());
            System.debug('@Checking getUrl: ' + tr.getUrl());
            System.debug('@Checking isCustom: ' + tr.isCustom());
        }

    }
}
0

There is a describe call available that gives you the mini icon URL that you can add to your Visualforce e.g.:

https://na3.salesforce.com/img/icon/contacts16.png

Based on Describing Tabs Using Schema Methods it looks like you will have to search for that icon though by perhaps matching with the app label and then the SObject name or just searching for the SObject name.

PS

You can find the type of an SObject from its ID using the Id.getSObjectType method. So to find the types:

RecentlyViewed[] recents = [
        SELECT Id, Name
        FROM RecentlyViewed
        ORDER BY LastViewedDate DESC
        LIMIT 10
        ];
Set<String> types = new Set<String>();
for (RecentlyViewed r : recents) {
    types.add(String.valueOf(r.Id.getSObjectType()));
}

and then they can be translated into the icon URLs via the describe data.

|improve this answer|||||
  • How we can link that class with RecentlyViewed object, example I use this query SELECT Id, Name FROM RecentlyViewed ORDER BY LastViewedDate DESC LIMIT 10,then how we can get the URL or icon using the value from SQL with DescribeTabResult class ? – unidha Sep 1 '15 at 3:14
  • @unidha See the PS in the answer. – Keith C Sep 1 '15 at 7:24
  • I updated my trial above.Still I am struggling to link it with RecentlyViewed,I loop appLabel but didn't get 'Home' tab.If I get it,is it possible to get the 10 items in RecentlyViewed object? – unidha Sep 1 '15 at 8:23
  • @unidha I suggest you match on the tr.getSobjectName() and remove the tsr.getLabel() match. – Keith C Sep 1 '15 at 9:56
  • thanks for fast reply.I notice RecentlyViewed object not covered by tab object.Refer to my code here:gist.github.com/unidha/db3c91dcfb8a42d74bb2 .In RecentlyViewed I retrieved Account,ListView and User but from DescribeTab I only retrieve Account. – unidha Sep 2 '15 at 9:16
0

I found way how create link that similar to Recent Item.

First create a wrapper class.

public class RecentItemWrapper{
         public Id itemId { get;set;}
         public String  objectUrl {get;set;}
         public String Name {get;set;}
  }

Then in get method, retrieve data from RecentlyViewed and contruct the url

 public List<RecentItemWrapper> getRecentItem(){

  recentItem=new List<RecentItemWrapper>();

  lstRecentItem  =[SELECT Id, Name  FROM RecentlyViewed ORDER BY LastViewedDate DESC LIMIT 10];

  for (RecentlyViewed r : lstRecentItem) {
      system.debug('@Checking... '+ String.valueOf(r.Id.getSObjectType()));
      Schema.DescribeSObjectResult sa = r.Id.getSObjectType().getDescribe();
      String prefixOrc = sa.getKeyPrefix();

      RecentItemWrapper wrapper = new RecentItemWrapper();
      wrapper.itemId=r.Id;
      wrapper.objectUrl=System.Url.getSalesforceBaseURL().toExternalForm()+'/'+r.Id;
      wrapper.Name=r.Name;
      system.debug('@Checking objectUrl = '+ wrapper.objectUrl);
      recentItem.add(wrapper);

     }

     return recentItem;

 }

In Visualforce Page,code something like this:

  <ul>
  <apex:repeat value="{!recentItem}" var="items">
        <li><a href="{!items.objectUrl}">{!items.Name}</a> </li>
  </apex:repeat>                 
  </ul> 
|improve this answer|||||

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.