Multiple objects in a single Visual Force page:
<apex:page controller="wrappersearchpage1CLR">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputText value="{!InputValue}" label="Search Multiple Objects"/>
<apex:commandButton value="Search" action="{!Search}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="Search Result">
<apex:pageBlockTable value="{!wrapAccountList}" var="acc">
<apex:column headerValue="Account Name">
<apex:outputText value="{!acc.acc.name}"></apex:outputText>
</apex:column>
<apex:column headerValue="Company Name">
<apex:outputText value="{!acc.com.name}"></apex:outputText>
</apex:column>
<apex:column headerValue="Contact LastName">
<apex:outputText value="{!acc.con.lastname}"></apex:outputText>
</apex:column>
<apex:column headerValue="Child Name">
<apex:outputText value="{!acc.child.Child_Name__c}"></apex:outputText>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
----------------------
public class wrappersearchpage1CLR {
public string InputValue{get;set;}
public List<wrapAccount> wrapAccountList{get;set;}
public string s{get;set;}
public Company__c com;
public Account acc;
Public wrappersearchpage1CLR(){
}
public pagereference search(){
wrapAccountList = new List<wrapAccount>();
Com = new Company__c();
acc = new account();
s = '%' + InputValue + '%';
for(Account a : [SELECT Id, Name, Phone FROM Account WHERE Name LIKE:s]){
wrapAccountList.add(new wrapAccount(a,com));
}
for(Contact con : [SELECT Id, lastName FROM contact WHERE lastName LIKE:s]){
wrapAccountList.add(new wrapAccount(con));
}
for(Company__c c : [SELECT Id, Name FROM company__c WHERE Name LIKE:s]){
wrapAccountList.add(new wrapAccount(acc,c));
}
for(ChildData__c c : [SELECT Id, Child_Name__c FROM ChildData__c WHERE Child_Name__c LIKE:s]){
wrapAccountList.add(new wrapAccount(c));
}
return null;
}
public class wrapAccount {
public Account acc {get; set;}
public Boolean selected {get; set;}
public string str {get;set;}
public Company__c com{get;set;}
Public contact con{get;set;}
public ChildData__c Child{get;set;}
public wrapAccount(contact c){
con = c;
}
public wrapAccount(Account a,Company__c c) {
acc = a;
com = c;
selected = false;
}
public wrapAccount(ChildData__c c){
child = c;
}
}
}
No comments:
Post a Comment