I have the following Controller and Component working together. My issue is that the acctWrapList isn't displaying to the page. I put in some debug logs and it's showing the account data in the logs but it's not getting displayed to the page itself. I've tried many sources but I'm still not able to display the accounts listed from the query results to the page.
My controller:
private void runQuery() {
//init wrapper class
acctWrapList = new List<accountWrap>();
try {
system.debug(accounts);
accounts = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 10');
//Adds search results to wrapper class
for(Account a: accounts){
acctWrapList.add(new accountWrap(a,false));
}
}
catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
System.debug('Error ' + e);
}
}
public void runQueryLoad(string c) {
soql2 = 'select Id, Owner.Id, Parent.Id, Parent.Name, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, Street_Address__c, City__c, State_Province__c, Zip_Postal_Code__c, Country_Code__c, Account_Intergraph_Line_of_Business__c, Industry, Type, Phone, Account_Category__c, RecordTypeId from account where name =: company';
if(c != null){
company = c;
system.debug(company);
//init wrapper class
acctWrapList = new List<accountWrap>();
try {
system.debug(accounts);
accounts = Database.query(soql2 + ' order by ' + sortField + ' ' + sortDir + ' limit 10');
//Adds search results to wrapper class
if(!accounts.isEmpty()){
for(Account a: accounts){
acctWrapList.add(new accountWrap(a,false));
system.debug(a);
}
}
else if(accounts.isEmpty()){
soql = 'select Id, Owner.Id, Parent.Id, Parent.Name, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry, Street_Address__c, City__c, State_Province__c, Zip_Postal_Code__c, Country_Code__c, Account_Intergraph_Line_of_Business__c, Industry, Type, Phone, Account_Category__c, RecordTypeId from account where name != null';
runQuery();
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'No possible matching Accounts were found. Please use the search parameters to find an account. '));
}
}
catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
System.debug('Error ' + e);
}
}
}
Visualforce Component:
<td valign="top" width="775">
<apex:pageBlock mode="edit" id="resultsA">
<apex:actionSupport event="onclick" reRender="resultsA" status="actionStatus"/>
<apex:actionStatus id="actionStatus" startText="Loading..." stopText="" />
<apex:pageBlockTable value="{!acctWrapList}" var="acctWrap" align="top" >
<apex:column >
<apex:inputCheckbox id="selectAccountRow" value="{!acctWrap.isSelected}" onselect="toggle(this)">
<apex:actionSupport event="onclick" action="{!selectAcct}" reRender="SCOutputPanel, accountFieldPanel, convertLeadPanel" />
</apex:inputCheckbox>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Account" action="{!toggleSort}" rerender="resultsA,debug" >
<apex:param name="sortField" value="Name" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<a href="/{!acctWrap.oAccount.Id}"
id="{!acctWrap.oAccount.Id}"
target= "_blank"
onblur="LookupHoverDetail.getHover('{!acctWrap.oAccount.Id}').hide();"
onfocus="LookupHoverDetail.getHover('{!acctWrap.oAccount.Id}', '/{!acctWrap.oAccount.Id}/m?retURL=%2F{!acctWrap.oAccount.Id}&isAjaxRequest=1').show();"
onmouseout="LookupHoverDetail.getHover('{!acctWrap.oAccount.Id}').hide();"
onmouseover="LookupHoverDetail.getHover('{!acctWrap.oAccount.Id}', '/{!acctWrap.oAccount.Id}/m?retURL=%2F{!acctWrap.oAccount.Id}&isAjaxRequest=1').show();">
{!acctWrap.oAccount.Name}
</a>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Country" action="{!toggleSort}" rerender="resultsA,debug">
<apex:param name="sortField" value="Country_Code__c" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!acctWrap.oAccount.Country_Code__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Industry" action="{!toggleSort}" rerender="resultsA,debug">
<apex:param name="sortField" value="industry" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!acctWrap.oAccount.industry}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Parent Account" action="{!toggleSort}" rerender="resultsA,debug">
<apex:param name="sortField" value="parent.name" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!acctWrap.oAccount.parent.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</td>
Wrapper Class:
// the soql without the order and limit
private String soql {get;set;}
// the soql that searches for existing account with lead name
private String soql2 {get; set;}
// the collection of contacts to display
public List<Account> accounts {get;set;}
//WrapperClass list for accounts searched
public List<accountWrap> acctWrapList {get; set;}
private String company;
//Wrapper Class set up and defined - used for the page
public class accountWrap{
public account oAccount{get;set;}
public boolean isSelected{get;set;}
public accountWrap(account a, boolean b){
this.oAccount=a;
this.isSelected=b;
}
}
//Checkbox action for selecting Account from the search results in the page
public void selectAcct(){
boolean checked = false;
for (accountWrap aWrapper : acctWrapList){
if (aWrapper.isSelected){
checked = true;
system.debug('AccountWrapper '+ aWrapper.oAccount.Id);
theAccount.acctData = aWrapper.oAccount;
system.debug('AccountSearch '+ theAccount.acctData);
system.debug(aWrapper.isSelected);
system.debug(theAccount);
}
}
if (!checked){
theAccount.acctData = null;
}
}
public void toggleCheck(){
boolean checked = false;
for (accountWrap aWrapper : acctWrapList){
if (aWrapper.isSelected){
checked = true;
aWrapper.isSelected = true;
}
}
<apex:repeat>
tag and display one or two elements from this wrapper inside a standard html table. Then you'll know it's getting to the vf page successfully.