+ Start a Discussion
Ashu sharma 38Ashu sharma 38 

Page Reference by passing Id

Hello,

I have scenerio when i click on name (List  field ),when i click on any existing name records in list should redirect to detail page of that particular record.

I am using custom link though it,i want to perform the action
Raj VakatiRaj Vakati
Try this code
 
HYPERLINK('/apex/mypage?id="+id,'Open Record','blank');

 
Akshay_DhimanAkshay_Dhiman
Hi,
Nitish

I want to explain to you the concept of redirecting to a detail page of the existing record in your list.
Here, in the code below I have made a data list of Account object which will redirect you to its detail page by clicking on any of the account names in that list.

VF Page:
 
<apex:page controller="AccountlistController" >
 <apex:form >
 <apex:pageBlock title="Account List">
  <apex:dataList value="{!acList}" var="ac" id="dt">
   <apex:commandLink value="{!ac.name}"  action="{!showaccount}" reRender="dt">
     <apex:param name="detailaccount" value="{!ac.id}"  />
      </apex:commandLink>
  </apex:dataList>
 </apex:pageBlock>
 </apex:form>
</apex:page>


The command line tag will invoke the (showaccount) method of controller apex class and the param tag will hold the id of the selected account.

Controller Class:
 
public class AccountlistController {
    public List<Account> acList{get;set;}
  public AccountlistController()
  {
     acList=[SELECT name from Account limit 10];
  }
       
 public Pagereference showaccount()
 {
    Id recordId= ApexPages.currentPage().getParameters().get('detailaccount');
     PageReference myPage=new PageReference('/'+recordId);
    
     return myPage;
 }
}


I hope this explanation will help you resolve your query. 
Mark, it as best answer if you find it helpful so that others can get help.

Thanks.
Akshay