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
swapna9swapna9 

Multiple object fields search

Hi,

 

I was able to search one field in one object using vf page and controller.But i want to search diiferent fileds from different objects in single vf page.

In my code i can search student name ( input field) from  student object.At the same time i want search account name( which is another input field).from account object.My problem is i am able to get the record in standard controller only.

 

Can any one guide me.....

 

here is my code:

 

<apex:page StandardController="Student__c" extensions="SearchAppointments " showHeader="false" sidebar="False">
<apex:form >
<table>
<apex:pageBlock >
<apex:outputText > <font size="2" color="blue" >Search Appointments</font></apex:outputText>
<tr>
<td><b> Name : </b> 
<apex:inputField value="{!Student__c.Name}"/>  
<apex:commandButton action="{!AppSearch}" value="Search Appointments"/>
</td>
</tr>
</apex:pageBlock>
</table><br></br><br></br>
<apex:pageBlock >
<apex:pageBlockSection columns="1" title="Results">
<table>
<tr align="center">
<td align="center">
<apex:pageBlockTable value="{!AppSearchData}" var="DS" title="Available Doctors" width="100%">
<apex:column value="{!DS.Name}"/>
</apex:pageBlockTable>
</td>
</tr>
</table>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

apex class:

Public class SearchAppointments {

public PageReference AppSearch() {
return null;
}

public Student__c AppSearch {get;set;}
public SearchAppointments (ApexPages.StandardController controller) {
AppSearch=(Student__c)controller.getRecord();
}

public List<Student__c> getAppSearchData(){
List<Student__c> listBd=[select Id,Name from Student__c where Name=:Appsearch.Name ];
return listBd;
}
}

 

Thanks in advance...

kiranmutturukiranmutturu

here u need to use SOSL..not the SOQL... check the docs here

swapna9swapna9

Thanks for ur reply,

 

can u please give me one example....

Naidu PothiniNaidu Pothini
	String StringToSearch = 'Test';

	String tablesFields = 'lead(Id, Email, Firstname, Lastname ), account(Id, Name)';

	String searchString = 'find \'' + StringToSearch + '\' in Name FIELDS ' + 'RETURNING ' + tablesFields;  

	List<List<sObject>> searchResults  = new List<List<sObject>>{};

	searchResults = search.query(searchString); 
	List<Lead> LeadList = new List<Lead>();
	List<Account> AccountList = new List<Account>;
	LeadList = ((List<Lead>)searchResults[0]);
	AccountList = ((List<Account>)searchResults[1]); 

 If you are searching through Leads and Accounts. Then this is how the code looks. Please make necessary modifications according to your requirement.

 

Let me know if you have any issues.