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
divay singhdivay singh 

how to open account info from search result in visualforce

I have created visualforce and apex class to search account. Now i want to click on the name which i get in result(Account name). So it should open new visual page with information
Maria Alexander 19Maria Alexander 19
Hi Divya,

Yes we can show the selected account information in the new visualforce page.

First Page:

<apex:page controller="Account_info">
  <apex:form >
  <apex:pageBlock >
  <apex:repeat value="{!acc}" var="a">
  <apex:commandLink action="{!comdlink}"> 
  {!a.Name}
  <apex:param assignTo="{!accountinfo}" name="{!a.Id}" value="{!a.Id}"/>
  </apex:commandLink><br/>
  </apex:repeat>
  </apex:pageBlock>
  </apex:form>
</apex:page>

First Controller

public class Account_info {

 public String comdlink {get;set;}
 
 public String accountinfo {get;set;}

 public List<Account> acc{get;set;}
 
 public Account_info(){
 
 acc=[select id,Name from account];
 
 } 

 public PageReference comdlink (){
 
 PageReference prf=new PageReference('apex/Account_DetailPage?id='+accountinfo);
 
 return prf;
 }
 
}


second Class:

<apex:page conntroller="Account_info2 ">
<apex:form>
<apex:pageBlock>
<apex:pageBlockTable value="{!acc}" var="ac">
<apex:column value="{!ac.Name}"/> 
//you can add more accoutnfields
</apex:pageBlock>
</apex:from>
</apex:page>
public class Account_info2 {

 public String comdlink {get;set;}
 
 public String accountinfo {get;set;}

 public List<Account> acc{get;set;}
 
 public Account_info(){
 
 comdlink=apexpages.currentpage().getparameters().get('id');
 
 acc=[select id,Name from account where Name=:comdlink];
 
 } 

}

I hope this code will help your sinario.

If you got anser please mark as best answer.