apex:outputlink Example
Example 1: Display the detail page of a record when click on it.
<apex:page sidebar="false" standardController="DataLoadTest__c" recordSetVar="records">
<style>
.headerRow th
{
display:none;
}
</style>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!records}" var="r">
<apex:column >
<apex:outputlink value="https://ap1.salesforce.com/{!r.Id}">{!r.Name}</apex:outputlink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Example2: Display Detail page using command links by passing Ids from VF page to Apex Class
Visualforce page
<apex:page sidebar="false" controller="Detailoutputlink1">
<style>
.headerRow th
{
display:none;
}
</style>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!records}" var="r">
<apex:column >
<apex:commandLink value="{!r.Name}" action="{!showDetail}">
<apex:param name="rId" value="{!r.Id}" assignTo="{!rId}"/>
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex class
public with sharing class Detailoutputlink1 {
public String rId{get;set;}
public PageReference showDetail() {
pagereference ref = new pagereference('https://ap1.salesforce.com/'+rId);
ref.setredirect(true);
return ref;
}
List<DataLoadTest__c> lstdlt = new List<DataLoadTest__c>();
public List<DataLoadTest__c> getRecords() {
lstdlt=[select Id,name from DataLoadTest__c];
return lstdlt;
}
}
Example3: outputlink for navigating vf page to google page
<apex:page sidebar="false" >
<apex:form >
<apex:outputlink value="http://www.google.co.in/">Google</apex:outputlink>
</apex:form>
</apex:page>
Example4: Display the Printable view page using output links
<apex:page sidebar="false" standardController="DataLoadTest__c" recordSetVar="records">
<style>
.headerRow th
{
display:none;
}
</style>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!records}" var="r">
<apex:column >
<apex:outputlink value="https://ap1.salesforce.com/{!r.Id}/p?retURL=/{!r.Id}">{!r.Name}</apex:outputlink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>