function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
madhumadhu 

click a record redirect to detail page

hi,
In vf page there are few records and i need to click on the "id" the record and it must redirect to the record detail page.


Please lt me know how to achieve this
Best Answer chosen by madhu
KaranrajKaranraj
Madhu - For the inline page use onclick event in the ouputlink to open the page in the new tab,instead of opening in the same iframe window.
Here is the code
<apex:outputlink value="#" onclick="window.open('/{!Account.Id}','_blank');">{!Account.Name}</apex:outputlink>


 

All Answers

KaranrajKaranraj
Use apex:outputLink visualforce tag to display Name in the hyperlink, when the user click the Name it will redirect to the detail page of that particular record page
<apex:outputLink value="/{!rec.Id}" target="_blank"> {!rec.Name} </apex:outputLink>

 
Ritesh Gupta 27Ritesh Gupta 27
Hi Madhu,

You need to pass "id" of the record on the click event(using action function) in order to redirect to record detail page and use PageReference Object to redirect the page as shown below.

PageReference pf = new PageReference('/' + <id>);
pf.setRedirect(true);
return pf;

You can also use javascript for this task. All the record detail page in salesforce have URL pattern
https://<server-instance>.salesforce.com/<record-id>
So you can redirect the page on above link by dynamically passing <record-id>
madhumadhu
Hi ritesh,

Thanks for your mail.

I have done it by passing the id(apex:param) to the page reference.

But the issue is it is a inline vfpage. and it is redirecting in same section rather than opening in a new page
KaranrajKaranraj
Madhu - For the inline page use onclick event in the ouputlink to open the page in the new tab,instead of opening in the same iframe window.
Here is the code
<apex:outputlink value="#" onclick="window.open('/{!Account.Id}','_blank');">{!Account.Name}</apex:outputlink>


 
This was selected as the best answer
madhumadhu
Hi karanraj,

i have written the code like this

   <apex:outputlink onclick="window.open('/{!v.id}','_blank')">{!v.id}</apex:outputlink>

it is displaing in anothet tab. so this is wirking fine.

But issues on the existing vf page that is inline vfpage it is saying as "URL DOES NOT EXIST"
 
madhumadhu
Hi Karanraj,

I just forgot to mention the value="#". so i just added it and now its working fine.

Thanks for the help.