When I press view link, the record page must open and it is not opening. Another one is and it is showing both search records and list of all records.

<apex:page standardController="Documents__c" extensions="Documentlist3,Documentsearch" recordSetVar="Member" showHeader="false" sidebar="false">
<apex:form >
      <apex:pageBlock mode="edit" id="block">
         <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
               <apex:outputLabel for="searchText">Search Text</apex:outputLabel>
               <apex:panelGroup >
                  <apex:inputText id="searchText" value="{!searchText}"/>
                  <apex:commandButton value="Go!" action="{!doSearch}"                                       rerender="block" status="status"/>
        <apex:actionStatus id="status" startText="requesting..."/>
        <apex:pageBlockSection title="Results" id="results" columns="1">
           <apex:pageBlockTable value="{!results}" var="l"                                rendered="{!NOT(ISNULL(results))}">
              <apex:column value="{!l.Name}"/>

    <apex:pageBlock >
        <apex:pageBlockTable value="{!DocList}" var="D">
                        <apex:column value="{!D.Name}"/>
                        <apex:column value="{!D.Description__c}"/>

                <apex:column >
                        <apex:commandLink value="View" action="{!viewcase}">
                        <apex:param name="Doclist" value="{!D.Id}"/>




public class Documentlist3 {
public Documents__c abcx{ get; set; }

    public List<Documents__c> DocList {get;set;}
    private ApexPages.StandardSetController standardController;
    private Set<Id> DocIds = new Set<Id>();

    public Documentlist3(ApexPages.StandardSetController standardController){
        this.standardController = standardController;
        DocList = new List<Documents__c>();
        for (Documents__c Doc : (List<Documents__c>)standardController.getSelected()){
        DocList = [SELECT  Id,Name,Description__c FROM Documents__c];

public Account viewcase() {
        return [SELECT Id, Name FROM Account
                WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];


public class Documentsearch {

    public Documentsearch(ApexPages.StandardSetController controller) {


    String searchText;
    List<Documents__c> results;

    public String getSearchText() {
        return searchText;

    public void setSearchText(String s) {
        searchText = s;

    public List<Documents__c> getResults() {
        return results;

    public PageReference doSearch() {
        results = (List<Documents__c>)[FIND :searchText RETURNING Documents__c(Name),Documents__c(Name)][0];
        return null;

I have 2 issues in this when

  1. When i am clicking the view button the record is not opening and
  2. When i am searching i am getting searching values separatley

I want if I search, the search results must show. Otherwise the document list must come. Please anyone solve this and help me


2 Answers 2


I see few issues why you link is not working: 1) DocList is list of Document__c records and then you are trying to query Account using Doc.Id which is id of the Document__c not account, so it won't find any Account record. 2) when you return account in the method it does not open new page with this record. You need to return PageReference to open new page, you can use method like this:

public PageReference viewcase() {
    return new PageReference('/' + accountId); // where accountId is Id of the account not document__c

or you can use a link on your page if you have a lookup or master detail relationship field called "Account__c" on your Document__c object to Account:

<apex:outputLink value="/{!D.Account__c}">View</apex:outputLink>

If I understood second issue correctly looks like for second issue you need to use boolean variable for example isSearch and set it to true if user searches to show section with results and add render to your section:

<apex:pageBlockSection render="{!isSearch}" title="Results" id="results" columns="1">

for another section you can add render="{!NOT(isSearch)}" to hide it if user searches and show when he is not searching.

  • i want to open the document record not account record,like we see in the standarded object we click on recordname the record will be open so i need that
    – ganesh
    Aug 22, 2014 at 5:22
  • You can do it this way: <apex:outputLink value="/{!D.Id}">View</apex:outputLink>
    – Paul Boiko
    Aug 22, 2014 at 16:03


public with sharing class DocumentsSearchController { //private ApexPages.StandardController controller {get; set;} public List documentList {get;set;} public string searchText {get;set;} public Boolean ShowPgTable{set;get;}

public DocumentsSearchController ()
    documentList = new List<Documents__c>();

// fired when the search button is clicked
public PageReference search() {
String qry = 'select id, Name, Description__c  from Documents__c ';
if(searchText!=null )
  qry += ' where Name LIKE \'%'+searchText +'%\' order by Name ';
qry+='LIMIT 1000';
documentList = Database.query(qry);
return null;



vf page

apex:page controller="DocumentsSearchController" tabStyle="Documents__c" showHeader="false" sidebar="false">

apex:form id="theForm">

<apex:sectionHeader title="Documents" />

<apex:pageBlock id="block">

  apex:outputLabel for="searchText"><B>Search Text :  </b></apex:outputLabel>
    <apex:panelGroup >
      <apex:inputText id="searchText" value="{!searchText}"/>
      <apex:commandButton value="Go" action="{!search}" rerender="theForm" status="status"/>
  <apex:actionStatus id="status" startText="requesting..."/>
  <apex:pageBlockSection title="Results" id="results" columns="1" >
    <apex:pageBlockTable value="{!documentList}" var="doc" id="thePageBlockTabele">
      <apex:column headerValue="Action">
        <apex:commandLink value="View" action="/{!doc.id}"/>
      <apex:column value="{!doc.Name}"/> 
      <apex:column value="{!doc.Description__c}"/> 

and the 2points above mentioned are solved and working fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .