3

I am trying to get the <apex:outputField> works as it works for a lookup field, which is a link pointing to the object and when you hover on it, it pops up with a dialog of the object info. However, I find it quite hard to get that without using a lookup field pointing to it. Name and id are both text fields. Is there anyway to get this without coding everything in html?

3
  • Does using the title attribute on the outputfield not fit your needs? You can mimic the pop-up dialog on hover that way, although it's not quite as pretty as the look-up one..
    – kbentsen
    Dec 18, 2014 at 3:51
  • I guess the major thing I want is the link.
    – Lance Shi
    Dec 18, 2014 at 4:02
  • How about wrapping your outputField in an outputLink? Never tried it before, but I think that works.
    – kbentsen
    Dec 18, 2014 at 4:09

2 Answers 2

10

You can add the same JS to the link that Salesforce adds. Here is an example.

<apex:outputLink id="complink" 
       onblur="LookupHoverDetail.getHover(this.id).hide();" 
       onmouseout="LookupHoverDetail.getHover(this.id).hide();" 
       onfocus="LookupHoverDetail.getHover(this.id, '/{!row['Contact']['AccountId']}/m?retURL=%2Fapex%2FCampaignCallList%3FscontrolCaching%3D1%26id%3D{!Camp.Id}&isAjaxRequest=1&nocache=1418312066674').show();" 
       onmouseover="LookupHoverDetail.getHover(this.id, '/{!row['Contact']['AccountId']}/m?retURL=%2Fapex%2FCampaignCallList%3FscontrolCaching%3D1%26id%3D{!Camp.Id}&isAjaxRequest=1&nocache=1418312066674').show();"
       value="/{!row['Contact']['AccountId']}">
    <apex:outputText value="{!row['Contact']['Account']['CUSTOM__Company_Name__c']}">
</apex:outputLink>
  • You do need to give the link an ID
  • inside the onmouseover and onfocus event handlers is a reference to the page you're calling from. In this case /CampaignCallList?Id={!a campaign id} but you should replace with your own details.
  • it's the URL that gets passed to LookupHoverDetail.getHover that determines the content of the hover. Make sure it's the ID of the record you want to view like /001000000000001?.....
  • Salesforce advise against using their JS like this as it isn't a published API and can be changed without notice, causing your code to stop working.
1
  • I can't get this working in lightning. I get cross-origin errors. is there a solution for lightning?
    – Donuts
    Aug 11, 2017 at 20:14
0

Its not possible on Standard Salesforce Detail Page, only Lookup / Master detail fields support it by default.

Nearest solution i can suggest is

  1. Override View page with custom VF page, No need of of custom Controller you can use Standard
  2. You can use very Simple CSS based popup code on your field something like this

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .