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
Chaitra GVChaitra GV 

Develop a visualforce page which comprises of an input box and search button

Develop a visualforce page which comprises of an input box and search button. If name is entered and the search button is clicked, the page should display name and designation with respect to the name entered.
I tried writing the code below. But it seems to be not working. Please help me to complete this code,

<apex:page controller = "DisplayDesig">
        <apex:form>
        <apex:pageBlock>
            <apex:pageBlockTable value = "{!jobs}" var = "j">
                <apex:inputField value = "{!j.Name}"/>
                </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
</apex:page>

(Controller to fetch designation from custom object:)

public class DisplayDesig {
    
    public static List<Job__c> provideDesig(String Name)
        {
           List<Job__c> result =[SELECT Id, Designation__c from Job__c where Name =: Name];
            return result;

        }
    
    
}



 
Best Answer chosen by Chaitra GV
NagendraNagendra (Salesforce Developers) 
Hi Chaitra,

Sorry for this issue you are facing.

Please find the sample code below which does the same.

Visual Force Page: 
<apex:page Controller="SearchInVFController">
    <apex:form>
        <apex:inputText value="{!searchKey}" label="Input"/>
        <apex:commandButton value="Search records" action="{!search}"/>
        <apex:commandButton value="Clear records" action="{!clear}"/>
        <apex:pageBlock title="Search Result">
            <apex:pageBlockTable value="{!acc}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Apex Controller:
public class SearchInVFController {
    public list <Account> acc {get;set;}
    public String searchKey {get;set;}
    public SearchInVFController( ) {
    }

    public void search(){
        string searchquery='select Name,id from account where name like \'%'+searchKey+'%\' Limit 10';
        acc= Database.query(searchquery);
    }

    public void clear(){
        acc.clear();
    }
}
Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra