I've bastardised some code which displays data from a salesforce object is a searchable table on a visualforece page. I had this working when the controller code was using but now I have another challenge which is getting it to work with a custom object. I have made the appropriate edits where I think they should be, plus saved the APEX class with no errors but when trying to reference it in the visualforce page I'm being told the controller cannot be found. Even though the object is deployed and the APEX class is active.
Below is the APEX Class:
public class PulseResponseController{
public String Name { get; set; }
private String soql {get;set;}
public LIST<TUQ_Response__c>TUQResponse {get;set;}
public String sortDir {
get {if(sortDir == null) {sortDir = 'asc';} return sortDir;}
set;
}
public String sortField {
get { if (sortField == null) {sortField = 'Name'; } return sortField; }
set;
}
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 100'; }
set;
}
public PulseResponseController(){
soql ='select Name, contact.name, Account__c, TUQ_Score__c, Date_of_attempted_contact__c, Pulse_Category_This_Score__c, How_could_we_get_you_to_a_10__c WHERE Outcome_of_attempted_contact__c = Contacted';
runQuery();
}
public void toggleSort() {
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
runQuery();
}
public void runQuery() {
try {
TUQResponse= Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 100 ');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
public PageReference runSearch() {
String Name= Apexpages.currentPage().getParameters().get('Name');
String contactName= Apexpages.currentPage().getParameters().get('contactName');
String TUQScore = Apexpages.currentPage().getParameters().get('TUQ_Score__c');
String Account = Apexpages.currentpage().getParameters().get('Account__C');
String Dateofattemptedcontact= Apexpages.currentPage().getParameters().get('Date_of_attempted_contact__c');
String Howcouldwegetyoutoa10= Apexpages.currentPage().getParameters().get('How_could_we_get_you_to_a_10__c');
String PulseCategory= Apexpages.currentPage().getParameters().get('Pulse_Category_This_Score__c');
soql ='select Name, contact.name, Account__c, TUQ_Score__c, Date_of_attempted_contact__c, Pulse_Category_This_Score__c, How_could_we_get_you_to_a_10__c WHERE Outcome_of_attempted_contact__c = Contacted';
if (!Name.equals(''))
soql +='and Name LIKE \''+String.escapeSingleQuotes(Name)+'+%\'';
if (!contactName.equals(''))
soql +='and contactName LIKE \''+String.escapeSingleQuotes(contactName)+'%\'';
if (!Account.equals(''))
soql +='and Account LIKE \''+String.escapeSingleQuotes(Account)+'%\'';
if (!PulseCategory.equals(''))
soql +='and PulseCategory LIKE \''+String.escapeSingleQuotes(PulseCategory)+'%\'';
runQuery();
return null;
}
}
And here is the visualforce page:
<apex:page controller="PulseResponseController" standardStylesheets="True" showHeader="false" sidebar="false">
<apex:form >
<apex:pageMessages id="errors" />
<apex:pageBlock title="Search for Pulse Scores" mode="edit">
<table width="100%" border="0">
<tr>
<td width="200" valign="top">
<apex:pageBlock title="Parameters" mode="edit" id="criteria">
<script type="text/javascript">
function doSearch() {
searchServer(
document.getElementById("Name").value,
document.getElementById("contactName").value,
document.getElementById("Account").value,
document.getElementById("PulseCategory").value
);
}
</script>
<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
<apex:param name="Name" value="" />
<apex:param name="contactName" value="" />
<apex:param name="Account" value="" />
<apex:param name="PulseCategory" value="" />
</apex:actionFunction>
<table cellpadding="2" cellspacing="2">
<tr>
<td style="font-weight:bold;">Response Name<br/>
<input type="text" id="Name" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Contact Name<br/>
<input type="text" id="contactName" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Client<br/>
<input type="text" id="Account" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Category<br/>
<select id="PulseCategory" onkeyup="doSearch();">
</select>
</td>
</tr>
</table>
</apex:pageBlock>
</td>
<td valign="top">
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!Name}" var="Name">
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Name" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Name" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Pulse_Response__c.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Client Name" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="contact.Name" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Pulse_Response__c.contact.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Client" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="account__c" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Pulse_Response__c.account__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Pulse Score" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="TUQ_Score__c" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Pulse_Response__c.TUQ_Score__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Pulse Category" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Pulse_Category_This_Score__c" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Pulse_Response__c.Pulse_Category_This_Score__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</td>
</tr>
</table>
<apex:pageBlock title="Debug - SOQL" id="debug">
<apex:outputText value="{!debugSoql}" />
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
</apex:page>
I'm, not proficient at coding yet so I'm sure I've missed something or made a glaring oversight but would appreciate some guidance here.