I'm working on a search page that searches through all the fields in multiple objects and used those searched fields results in Visualforce page to show the search results and I'm stuck on how do you show search field results on VF, remember the search fields results come from different sobject1 or sobject2 etc..., I will try to demonstrate here what I mean by that.
PS: For the sake of simplicity I'm using standard object as an example but I'm using custom objects.
WrapperClass:
public class SearchWrapperClass {
public List<Account> aAccounts {get;set;}
public List<Contact> cContacts {get;set;}
public SearchWrapper(List<Account> a, List<Contact> c) {
this.aAccounts= a;
this.cContacts= c;
}
}
Apex Controller:
public List<SearchWrapperClass> mySearchWrapper {get;set;}
String searchquery ='FIND\'Edge*\'IN ALL FIELDS RETURNING Account(Id, Name),Contact(FirstName, LastName)';
List<List<SObject>> searchList = search.query(searchquery);
List<SearchWrapperClass> searchWrapperList = new List<SearchWrapper>();
Account[] searchAccounts = (Account[])searchList1[0];
Contact[] searchContacts = (Contact[])searchList1[1];
searchWrapperList.add(new SearchWrapper(searchAccounts,searchContacts));
mySearchWrapper = searchWrapperList;
Visualforce page:
Now, the problem is here I'm trying to show the search results so I should be able to show what is in the Account or Contact something like this I have attempted but does not work.
Error: Unknown property 'SearchWrapperClass.Name'
<apex:pageBlock title="Search Result" >
<apex:pageblockTable value="{!mySearchWrapper}" var="a">
<apex:column value="{!a.Name}"/>
</apex:pageblockTable>
</apex:pageBlock>
tried this and works but the problem with this approach is that I'm unable to query the Contact, how do I get the Contact search result in the pageBlockTable?:
<apex:pageBlock title="Search Result" >
<apex:pageblockTable value="{!mySearchWrapper[0].aAccounts}" var="a">
<apex:column value="{!a.Name}"/>
</apex:pageblockTable>
</apex:pageBlock>
Here is what I'm after to get or if you have a better solution please share. this is just a pseudo-code
<apex:pageblockTable value="{!mySearchWrapper}" var="a">
<apex:column value="{!a.aAccounts.Name}"/>
<apex:column value="{!a.aContacts.Name}"/>
</apex:pageblockTable>
Any thoughts?