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
sales4cesales4ce 

Help:Trying to build a custom search on Accounts!

Hi,

 

I am new to visualforce.What i am trying to do is:

 

Create a custom search kind of functionality and return results back to VF page based on the values selected.

 

For this :

 

1) I created a new Visualforce page, in which i take two standard Fields of Account ( Type and Rating).

2) I have a button on VF page "Search", when clicked takes values entered in Type and Rating and then returns results.

3) I have taken Standard Controller of "Account" and Extensions for this purpose

 

But, i am unable to see the results, what it shows is "sforce", under results section.

To my surprise, there are no errors also.

 

My VF code:

<apex:page standardController="Account" extensions="customSearch">
    <apex:form>
        <apex:pageBlock title="Custom Search" mode="Edit">
            <apex:pageblockSection title="Select Fields" columns="1" >
                <apex:inputField value="{!Account.Type}"/>
                <apex:inputField value="{!Account.Rating}"/><br/>                                                               
            </apex:pageblockSection>   
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Search" action="{!doSearch}"/>                 
            </apex:pageBlockButtons>                                                         
        </apex:pageBlock>
        
        <apex:pageBlock title="Search Results">
            <apex:pageBlockTable value="{!results}" var="Accts">
                <apex:column headerValue="Account Name">
                    <apex:outputText value="{!Accts.Name}">
                    </apex:outputText>
                 </apex:column>
                 <apex:column headerValue="Account Type">
                    <apex:outputText value="{!Accts.Type}">
                    </apex:outputText>
                 </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
    
</apex:page>

 

 

My Apex class for Controller Extension:

 

public class customSearch {

    public customSearch(ApexPages.StandardController controller) {

    }
   String Account_Type;
   public String getAccount_Type(){
       return Account_Type;
   }
   public void setAccount_Type(string Account_Type){
       this.Account_Type=Account_Type;
      }
    
    public List<Account> results=new List<Account>();
    
    public PageReference doSearch(){
        results=[Select Name, Type from Account Where Type=:Account_Type];
        return null;
        }
        
     public List<Account> getResults(){
         return results;
        }
}

 

Can anybody help me with this. 

 

Thanks in advance!

 

Sales4ce

visualforce_devvisualforce_dev

Hi,

 

I tried the same code without standard controller, and its working fine..

 

changes

 

<apex:PageblockSection title="Select Fields" columns="1" >
                <apex:inputField value="{!Acc.Type}"/>
                <apex:inputField value="{!Acc.Rating}"/><br/>                                                              
            </apex:PageblockSection>

<apex:PageBlock title="Search Results"> <apex:PageBlockTable value="{!results}" var="Accts"> <apex:column headerValue="Account Name"> <apex:OutputText value="{!Accts.Name}"> </apex:OutputText> </apex:column> <apex:column headerValue="Account Type"> <apex:OutputText value="{!Accts.Type}"> </apex:OutputText> </apex:column> </apex:PageBlockTable> </apex:PageBlock>

 

public Account acc = new Account(); public Account getacc() { return acc; }

 

PratibhPratibh

Hello,

 

It should work with standard controller too. Its not working because the datgrid is not rerendered after button is clicked.

Change the return type of method attached to commadbutton to void from PageReference and then rerender the pageBlock which has table.

 

Controller:

 

public void search(){

.....

}

 

Page:

 <pageBlock id="myPageBlock">

      <apex:pageBlockTable value=".." var="..." >

       </apex:pageBlockTable>

<apex:pageBlock>

 

<apex:commandButton action="{!search}" rerender="myPageBlock"/>

 

 

This should work.

sales4cesales4ce

Hello,

 

Thanks People!

 

It still deos not work for me both ways.I am still surprised, it does not throw any error.

 

In the List , it only shows "sforce".

 

Am i missing anything still?

 

Thanks,

Sales4ce