0

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.

1 Answer 1

0

You need a public property on the controller to expose an instance of Pulse_Response__c. Like this:

public Pulse_Response__c PulseRes {get; set;}

You then need to set this up (perhaps in the constructor?)

And then update your visualforce - change:

<apex:outputField value="{!Pulse_Response__c.Name}"/>

to:

<apex:outputField value="{!PulseRes.Name}"/>

And change all the other references in your page too

Edit - sobject is actually called TUQ_Response__c

You need a public property on the controller to expose an instance of Pulse_Response__c. Like this:

public TUQ_Response__c PulseRes {get; set;}
6
  • is that not what this line is doing: public LIST<TUQ_Response__c>TUQResponse {get;set;} The API name of the object is TUQ_Response__c Commented Dec 11, 2014 at 14:17
  • That line is creating a public property whose data type is a LIST of TUQ_Response__c objects rather than a single instance. Your page doesn't seem to reference that list. Also the page would need to select a particular record within the list to access its fields.
    – Force Hero
    Commented Dec 11, 2014 at 14:21
  • As an aside your SOQL appears to be missing a FROM clause (hence I couldn't confirm the name of the object)
    – Force Hero
    Commented Dec 11, 2014 at 14:22
  • hmm ok, I've done that but seem to bet getting a different error now which references the runSearch public pageReference on line 42: 'public PageReference runSearch()' Commented Dec 11, 2014 at 16:47
  • What's the error?
    – Force Hero
    Commented Dec 11, 2014 at 17:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .