0

How can I use a output link that would display the name of an account and when clicked would direct the user to that account's page? Here is what I have so far

<apex:pageBlockSectionItem >
    <apex:outputPanel id="detailedSection" >
        <apex:outputLink value="/!{selectedID}">
            <apex:outputText value="{!accountName}"/>
        </apex:outputLink>      
    </apex:outputPanel>
</apex:pageBlockSectionItem>

The idea is that the rest of the page is displaying a list of accounts and whenever one of them is clicked it will refresh this section. This section will have more detailed information (not implemented yet) as well as the account's name which should be a link to that account's main page

My issue is that this visualforce page is part of a layout of an account or contact page. So when I click this button all it does is redirect within the small chunk that is allocated to this particular visualforce page. What I want is for the entire window to go to the URL for the account

  • 2
    Check bobbuzzard.blogspot.co.uk/2011/05/… for some inspiration how to change the parent window's URL (because Visualforce is in iframe in standard page layout). Might be as simple as slapping <a href="#" onclick="window.top.location='/{!selectedid}';">{!accountName}</a> – eyescream Jun 17 '14 at 20:03
  • @eyescream you were absolutely right. If you make it an answer I'll be sure to set it so you get the points. – Louis Pujol Jun 17 '14 at 20:09
  • Nah, I like Ralph's "top" even better than this one :) Less Javascript, more regular HTML. and hopefully will work even in weird contexts like Service Cloud Console that does funny stuff to links. – eyescream Jun 17 '14 at 20:11
5

In general you're link looks good, the issue you're running into is because inline visualforce pages (those displayed on a page layout) are in iFrames. Links within in iframe, only apply to the iframe by default. However you can get it to open in the full window by by changing the target of the link to "_top"

_top Opens the linked document in the full body of the window

see W3 Schools a target attribute docs

You can also improve usability by using URLFOR, which will handle things for you like the return URL and overrides, but it's not strictly necessary.

<apex:outputLink target="_top" value="{!URLFOR($Action.Account.View,selectedId)}">
   {!accountName}
</apex:outputLink>

If you weren't in an iframe you could also just use apex:outputfield which if you tie it to an id field will display it as a link that you can hover over to get the mini page layout.

<apex:outputField value="{!oppRecord.accountId}"/>
| improve this answer | |
  • 1
    w3fools.com :P – eyescream Jun 17 '14 at 20:12
  • Okay now what if I wanted to extend this to be a list of contacts and accounts? And it could redirect to either of those pages. It looks like your solution would only work for viewing accounts. – Louis Pujol Jun 17 '14 at 20:18
  • This forum doesn't really work for follow-up questions, please post as another question. That said, I'd suggest a little reading on URLFOR, you already know how to make a link for the account, shouldn't be too hard to get to a contact – Ralph Callaway Jun 17 '14 at 20:20

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.