+ Start a Discussion
symantecAPsymantecAP 

Attaching ID to the hyperlink

Hi Developers. 

 

Here is my requirement, As to How can I attach the record ID to the Link. I am displaying list of product code and Product name as link on a VF page and its a custom comtroller. How do i pass on the link so that once when click the product code or name it redirects to the record

Here is my VF code.

<apex:page controller="ProductPriceBook23" tabStyle="Product2">

<apex:pageBlock >
         <h1><u>Report : Products and PriceBooks for Region= NA and Product Family=PRODUCT </u>  </h1>
 </apex:pageBlock> 
    



    <apex:pageBlock >
        <apex:pageblockTable value="{!products}" var="product">
                    <apex:column headerValue="Product Code" width="150">
                    <apex:outputLink value="https://c.cs4.visual.force.com/">  {!product.prod.ProductCode} </apex:outputLink>
                    </apex:column>
                    
                     <apex:column headerValue="Product Name" width="500">
                    <apex:outputLink value="https://c.cs4.visual.force.com/">  {!product.prod.name} </apex:outputLink>
                    </apex:column>

 Thanks All

 

Best Answer chosen by Admin (Salesforce Developers) 
vhanson222vhanson222

While that is more dynamic than hard-coding the domain info, i don't believe you need to have that...

 

Example below shows how i have been handling dynamic links.  it's simple and it seems to work well.

 

 

<a href="/{!product.prod.id}">{!product.prod.name}</a>

 

 

All Answers

Jake GmerekJake Gmerek

All you do is add the id of the record to the end of your URL.  You may have to modify the controller to make it work depending on how the controller is written, but your VF page could look like this:

<apex:page controller="ProductPriceBook23" tabStyle="Product2">

<apex:pageBlock >
         <h1><u>Report : Products and PriceBooks for Region= NA and Product Family=PRODUCT </u>  </h1>
 </apex:pageBlock> 
 <apex:pageBlock >
   <apex:pageblockTable value="{!products}" var="product">
     <apex:column headerValue="Product Code" width="150">
     <apex:outputLink value="https://c.cs4.visual.force.com/{!product.id}">         {!product.prod.ProductCode} </apex:outputLink>
                    </apex:column>
                    
                     <apex:column headerValue="Product Name" width="500">
                    <apex:outputLink value="https://c.cs4.visual.force.com/{!product.id}">  {!product.prod.name} </apex:outputLink>
                    </apex:column>

 

 

Rahul S.ax961Rahul S.ax961

For more dynamic url, Add below to your code:

 

Class:

 

Public Class ProductPriceBook23
{

public string strServerUrl
{ get;set; }

public ProductPriceBook23()
{
strServerUrl = 'https://' + ApexPages.currentPage().getHeaders().get('Host') + '/';
}
}

 

Page:

 

<apex:page controller="ProductPriceBook23" tabStyle="Product2">

<apex:pageBlock >
<h1><u>Report : Products and PriceBooks for Region= NA and Product Family=PRODUCT </u> </h1>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageblockTable value="{!products}" var="product">
<apex:column headerValue="Product Code" width="150">
<apex:outputLink value="{!strServerUrl}{!product.prod.ProductCode}"> {!product.prod.ProductCode} </apex:outputLink>
</apex:column>

<apex:column headerValue="Product Name" width="500">
<apex:outputLink value=" {!strServerUrl}{!product.prod.ProductCode}"> {!product.prod.name} </apex:outputLink>
</apex:column>

 

vhanson222vhanson222

While that is more dynamic than hard-coding the domain info, i don't believe you need to have that...

 

Example below shows how i have been handling dynamic links.  it's simple and it seems to work well.

 

 

<a href="/{!product.prod.id}">{!product.prod.name}</a>

 

 

This was selected as the best answer
aballardaballard

The urlfor function is the official supported way to get the url for going to a standard page. 

symantecAPsymantecAP

Thanks every one. ..I tried  <a href="/{!product.prod.id}">{!product.prod.name}</a>

Its magic .. Beauty of development. 

Rahul S.ax961Rahul S.ax961

Thanks for reminder,

I almost forgot that. :)