You need to sign in to do that
Don't have an account?

Custom search page development
Hi
I have utilised the excellent demo from Jeff Douglas at http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/ for building a custom dynamic search page in visual force. There is a great demo app there.
I have amended the code so that it works from my custom object. The page works fine, but I have an extra function that I would like but am not sure how to develop.
In the search results on my VF page I want to be able to click on the name of each custom objects record so that it opens the record in the normal layout for the custom object. The custom object has a master detail relationship to Contacts and the field for this relationship has the link automatically displayed. Can anyone enlighten me as to the peice of code I need to allow the Name field to be clickable?
The code I have in the VF page for this field is:
Many thanks in advance
Justyn
Bingo! Words cannot express my delight. I now just need to move on to Apex tests so that I can move it over to my production system.
many thanks
Justyn
All Answers
Hello,
Without seeing all the code it is hard to know for sure, but looking at the demo app that you linked to above, you should be able to make your changes with two edits.
1st - in the SOQL query that is built in the constructor of the controller you need to add ID as one of the fields being queryed. This is so that you can build the URL for the Link.
2nd - Change your code block that you showed above to the following:
<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:outputlink value = "/{!counselling_practice.id}"> <apex:outputField value="!counselling_practice.name}"/> </ apex:outputlink> </apex:column>
Notice all we did was wrap your outputfield in an output link and used the id from step one as the value, but do not forget the leading slash.
Hope this helps.
Hi
Thanks for the helpful tip. I followed the two steps, but must have made an error on the first one as I got an error saying value for outputField is not a dynamic binding! I don't know if you are able to but I have copied below working copies of the code for the controller and VF Page. It will be interesting to see the changes.
Kind regards
Justyn
CONTROLLER
VISUALFORCE PAGE:
<apex:page controller="ReferralSearchController" sidebar="false">
<apex:form >
<apex:pageMessages id="errors" />
<apex:pageBlock title="Find Me A Counsellor / Psychotherapist!" 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("member").value,
document.getElementById("Counselling_Service").options[document.getElementById("Counselling_Service").selectedIndex].value,
document.getElementById("fee_amount").value,
document.getElementById("Referral_County").options[document.getElementById("Referral_County").selectedIndex].value,
document.getElementById("Practice_Area_Town").value,
document.getElementById("Practice_City_County").value,
document.getElementById("for_whom").options[document.getElementById("for_whom").selectedIndex].value,
document.getElementById("gender").value
);
}
</script>
<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
<apex:param name="name" value="" />
<apex:param name="member" value="" />
<apex:param name="Counselling_Service" value="" />
<apex:param name="fee_amount" value="" />
<apex:param name="Referral_County" value="" />
<apex:param name="Practice_Area_Town" value="" />
<apex:param name="Practice_City_County" value="" />
<apex:param name="for_whom" value="" />
<apex:param name="gender" value="" />
</apex:actionFunction>
<table cellpadding="2" cellspacing="2">
<tr>
<td style="font-weight:bold;">Name<br/>
<input type="text" id="name" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Member<br/>
<input type="text" id="member" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Counselling_Service<br/>
<select id="Counselling_Service" onchange="doSearch();">
<option value=""></option>
<apex:repeat value="{!Counselling_Service}" var="Counselling_Service">
<option value="{!Counselling_Service}">{!Counselling_Service}</option>
</apex:repeat>
</select>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Fee Amount<br/>
<input type="text" id="fee_amount" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Referral County<br/>
<select id="Referral_County" onchange="doSearch();">
<option value=""></option>
<apex:repeat value="{!Referral_County}" var="Referral_County">
<option value="{!Referral_County}">{!Referral_County}</option>
</apex:repeat>
</select>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Practice Area/Town<br/>
<input type="text" id="Practice_Area_Town" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Practice City/County<br/>
<input type="text" id="Practice_City_County" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">For Whom<br/>
<select id="for_whom" onchange="doSearch();">
<option value=""></option>
<apex:repeat value="{!for_whom}" var="for_whom">
<option value="{!for_whom}">{!for_whom}</option>
</apex:repeat>
</select>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Gender<br/>
<input type="text" id="gender" onkeyup="doSearch();"/>
</td>
</tr>
</table>
</apex:pageBlock>
</td>
<td valign="top">
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!counselling_practices}" var="counselling_practice">
<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="{!counselling_practice.name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Member" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="member" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!counselling_practice.Member__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Counselling_Service" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Counselling_Service" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!counselling_practice.Counselling_Service__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Fee Amount" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="fee_amount" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!counselling_practice.Fee_Amount__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Referral County" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Referral_County" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!counselling_practice.Referral_County__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Practice Area/Town" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Practice_Area_Town" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!counselling_practice.Practice_Area_Town__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Practice City/County" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Practice_City_County" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!counselling_practice.Practice_City_County__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="For Whom" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="for_whom" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!counselling_practice.For_Whom__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Gender" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="gender" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!counselling_practice.Gender__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>
Taking a look at it, the method I described should work. Just for clarity I made a quick test page and controller that shows what I am taking about.
Would you make the changes, and if you get the same error, will you post the sections of the code that you modified so that I can take a look at that?
Hi Jake
I am definitely out of my league here. I have added the ID to the two soql listed in the search controller (original listed earlier):
and also added in your sample code to the VF Page:
<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:outputlink value="/{!counselling_practice.id}">
<apex:outputField value="!counselling_practice.name}"/>
</apex:outputlink>
</apex:column>
As the original code is fairly complex it is beyond me to work out what to do which is a real shame and the code is so close to what I want to achieve. If the code for the VF page is correct, then the error I get is down to the controller code. I do know that the above soql is error free when using Force.com explorer.
Kind regards
Justyn
Justyn, your code is missing a { on the name field:
<apex:outputField value="!counselling_practice.name}"/>
should be:
<apex:outputField value="!{counselling_practice.name}"/>
Sometimes those errors can be the hardest to find. Try that and let me know if it works.
Bingo! Words cannot express my delight. I now just need to move on to Apex tests so that I can move it over to my production system.
many thanks
Justyn
No problem
Were you successfull in creating the Apex Test case for this controller?
Hi
I've not been able to do the Apex Test controllers as it is definitely out of my league without some training. A real shame and I am having to see if I can find a developer to aid.
Justyn
I have managed to come up with a test method with 72% code coverage. Would like help in increasing the coverage.
Apex Controller:
Test Method:
Wow. That is very quick, and very helpful. If anyone can push the coverage to over 75% I would be much indebted.
Justyn
Can one of you indicate which lines are not being covered by the test currently?
The Red ones are not being covered.
Apex Controller:
This should give you good code coverage, but please notice my note for proper testing. It is also possible that without creating some records as mentioned that the test will fail when deployed to production in a clean (no data) environment since there will be no records to query.
Thanks Jake, this has been really helpful.Raised the coverage to 88%
Hi Jake
It's great that someone is helpful us work out our testing! I've taken the code you suggested and applied to my situation but get the following error:
Error: Compile Error: expecting a right parentheses, found 'to' at line 34 column 24
The relevant line of the code is:
System.assert(check to see if it returned the soql string);
Any helpful thoughts?
Justyn
System.assert(check to see if it returned the soql string);
Sorry, the "check to see if it returned the soql string" was in the nature of a comment. You can actually comment that line out to test your code, because essentially there is two parts to testing, code coverage and ensuring your code is doing what it is actually supposed to do. Sales force requires the first, the second is just best practice for the user to ensure that your program does what you want it to do. After you test it, you will probably want to add something back in, but it is not required.
Hi Jake
The test controller is up to 40% which is good progress. I've copied below the debug log if it can be of help. I will also copy the full test controller code.The original controller code is in first couple of entries to this discussion. If you can help that would be great.
Justyn
08:41:28.869 (869253000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object
22.0 APEX_CODE,FINE;APEX_PROFILING,FINE;DB,INFO;VALIDATION,INFO;WORKFLOW,FINEST
08:41:28.451 (451713000)|EXECUTION_STARTED
08:41:28.451 (451823000)|CODE_UNIT_STARTED|[EXTERNAL]|01pT0000000AFsZ|ReferralSearchControllerTest.ReferralSearchControllerTest
08:41:28.451 (451922000)|METHOD_ENTRY|[2]|01pT0000000AFsZ|ReferralSearchControllerTest.ReferralSearchControllerTest()
08:41:28.451 (451994000)|METHOD_EXIT|[2]|ReferralSearchControllerTest
08:41:28.452 (452188000)|METHOD_ENTRY|[1]|Test.Test()
08:41:28.452 (452255000)|METHOD_EXIT|[1]|Test
08:41:28.454 (454662000)|METHOD_ENTRY|[1]|01pT0000000A9jv|ReferralSearchController.ReferralSearchController()
08:41:28.455 (455773000)|METHOD_EXIT|[1]|ReferralSearchController
08:41:28.455 (455856000)|CONSTRUCTOR_ENTRY|[37]|01pT0000000A9jv|<init>()
08:41:28.456 (456226000)|METHOD_ENTRY|[29]|01pT0000000A9jv|ReferralSearchController.runQuery()
08:41:28.484 (484108000)|SOQL_EXECUTE_BEGIN|[44]|Aggregations:0|select name, ID, member__c, Counselling_Service__c, Therapeutic_Approach__c, fee_amount__c, Referral_County__c, Practice_Area_Town__c, Practice_City_County__c, for_whom__c, gender__c, donations__c, negotiable__c, free_service__c from counselling_practice__c where name != null and currently_active__c = True order by name asc limit 20
08:41:28.862 (862631000)|SOQL_EXECUTE_END|[44]|Rows:5
08:41:28.863 (863065000)|METHOD_EXIT|[29]|01pT0000000A9jv|ReferralSearchController.runQuery()
08:41:28.863 (863302000)|CONSTRUCTOR_EXIT|[37]|01pT0000000A9jv|<init>()
08:41:28.863 (863566000)|METHOD_ENTRY|[39]|01pT0000000A9jv|ReferralSearchController.runSearch()
08:41:28.868 (868745000)|EXCEPTION_THROWN|[72]|System.NullPointerException: Attempt to de-reference a null object
08:41:28.868 (868936000)|METHOD_EXIT|[39]|01pT0000000A9jv|ReferralSearchController.runSearch()
Controller
}
@isTest
private class ReferralSearchControllerTest {
static testMethod void ReferralSearchControllerTest() {
/*Also to be sure that this class works correctly we should create and
*insert some records for the object that we are running the query on
*(Counselling_Practice__c in the above example) and then after we call runSearch()
*check the counselling list list and ensure that the first record would be the
*first record that is returned. For example to check the sort by firstname,
*we would create a candidate with the first name 'aaaaaaa'. This would
*ensure that the record we created would be returned first and we can check
*to ensure that we get the proper record back. We would have to call runSearch()
*directly after we do "pg.getParameters().put('firstName', 'test first name');"
*so that it would sort by first name, then we would have to unset the firstname
*parameter and repeat the process for the next parameter and so on. But I will
*leave that to you
*/
//instantiate a page
PageReference pg = Page.ReferralSearch;
Test.setCurrentPage(pg);
pg.getParameters().put('Name', 'test first name');
pg.getParameters().put('Counselling_Service', 'test Addiction');
pg.getParameters().put('Therapeutic_Approach', 'test C.B.T.');
pg.getParameters().put('Referral_County', 'test Wicklow');
pg.getParameters().put('Practice_Area_Town', 'test Bray');
pg.getParameters().put('Practice_City_County', 'test Shankhill');
pg.getParameters().put('for_whom', 'test Couples');
pg.getParameters().put('gender', 'test male');
pg.getParameters().put('donations', 'test Yes');
pg.getParameters().put('negotiable', 'test No');
pg.getParameters().put('fee_amount', 'test 70');
pg.getParameters().put('free_service', 'test Yes');
// instantiate the controller
ReferralSearchController controller=new ReferralSearchController();
System.assert(controller.runSearch() == null);
String testDebugSoql = controller.debugSoql;
// System.assert(check to see if it returned the soql string);
controller.toggleSort();
System.assertequals (controller.sortDir, 'desc');
List<String> testCounselling_Service = new List<String>();
testCounselling_Service = controller.Counselling_Service;
System.assertequals (testCounselling_Service[0], 'First Picklist Value');
List<String> testTherapeutic_Approach = new List<String>();
testTherapeutic_Approach = controller.Therapeutic_Approach;
System.assertequals (testTherapeutic_Approach[0], 'First Picklist Value');
List<String> testReferral_County = new List<String>();
testReferral_County = controller.Referral_County;
System.assertequals (testReferral_County[0], 'First Picklist Value');
List<String> testfor_whom = new List<String>();
testfor_whom = controller.for_whom;
System.assertequals (testfor_whom[0], 'First Picklist Value');
//to test the catch clause we need to make the query fail
//I think that this will do it but I am not sure
controller.sortField = 'Some invalid sort field';
controller.runQuery();
}
The test result detail from the Apex test is below. I assume the main issue are erroros on lines 72 & 39 :
Apex Test Result Detail
Class.ReferralSearchControllerTest.ReferralSearchControllerTest: line 39, column 23
External entry point
Justyn, which line in referral search controller is line 72? I know approx. where it is, but I want to make sure I am looking at the right one.
Hi
I've copied the relevant lines below:
Class.ReferralSearchController.runSearch: line 72, column 10
72 if (!member.equals(''))
73 soql += ' and member__c LIKE \''+String.escapeSingleQuotes(member)+'%\'';
Class.ReferralSearchControllerTest.ReferralSearchControllerTest: line 39, column 23
39 System.assert(controller.runSearch() == null);
Kind regards
Justyn
Hey Justyn,
It looks like your test code is not initializing the member variable to anything. Normally when the runSearch function is called, all of your variables are being initialized to "" by your VF page, but since there is no VF page to do that you have to explicitly do that in the test code.
pg.getParameters().put('Member', 'Test Member');
That should take care of this error at least.
Up to 80% coverage with that little change! I've just tried to deploy it to the Production setting but it says I only have 70% coverage. Do you think we can easily tweek extra?
Justyn
Show me what is not covered still, you may have a problem though. Salesforce requires that to deploy any code, ALL of your code must total 75% coverage, so it is possible that we could get this code to 100% and still not get your entire org to 75%, but it depends on the amount of other code you have. Anyway, that was just a heads up, if you show me what is still not being covered, I will do my best to help you.
Hi
I had a sudden thought that I should also deploy the ReferralSearchControllerTest as well as my ReferralSearchController and ReferralSearch Visualforce page? When validating this in Production it fails for this reason:
Line 50 in the Test Controller is:
System.assertequals (testCounselling_Service[0], 'First Picklist Value');
Should it say First Picklist Value, or be the actual value?
I can't get a revised coverage value until I've done this bit. Feels like we are so close to pushing it over the line!
Justyn
It should be the actual value.
We have 100% code coverage. I've just successfully deployed it to our Production setting. Thank you ever so much!
Justyn
No problem, glad to help!!
Hi Jake,
I am trying to implement the same type of custom dynamic search for a Custom Object Candidates which contains a particular Canidate record. But the same type of code is not working for me.
Please check my VF Page code and Controller below and correct me if there is something wrong i am following.
------------------------------------------------------------------------------------------------
Apex Controller
------------------------------------------------------------------------------------------------
public with sharing class CandidateSearchController {
// the soql without the order and limit
private String soql {get;set;}
// the collection of Candidates to display
public List<Candidate__c> candidates {get;set;}
public String firstName{get;set;}
public String lastName{get;set;}
public String emailid {get;set;}
// the current sort direction. defaults to asc
public String sortDir {
get { if (sortDir == null) { sortDir = 'asc'; } return sortDir; }
set;
}
// the current field to sort by. defaults to last name
public String sortField {
get { if (sortField == null) {sortField = 'Last_Name__c'; } return sortField; }
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
set;
}
// init the controller and display some sample data when the page loads
public CandidateSearchController() {
soql = 'Select Id, Last_Name__c, First_Name__c, Email__c From Candidate__c';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort() {
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery() {
try {
candidates = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
firstName = Apexpages.currentPage().getParameters().get('firstName');
lastName = Apexpages.currentPage().getParameters().get('lastName');
emailid = Apexpages.currentPage().getParameters().get('emailid');
soql = 'Select Id, Last_Name__c, First_Name__c, Email__c From Candidate__c';
if (!firstName.equals(''))
system.debug('First Name of the candidate is: **************'+firstName);
soql += 'and First_Name__c LIKE \''+String.escapeSingleQuotes(firstName)+'%\'';
if (!lastName.equals(''))
soql += 'and Last_Name__c LIKE \''+String.escapeSingleQuotes(lastName)+'%\'';
if (!emailid.equals(''))
soql += 'and Email__c LIKE \''+String.escapeSingleQuotes(emailid)+'%\'';
// run the query again
runQuery();
return null;
}
}
-------------------------------------------------------------------------------------
VisualForce Page
-------------------------------------------------------------------------------------
<apex:page controller="CandidateSearchController" sidebar="false">
<apex:form >
<apex:pageMessages id="errors" />
<apex:pageBlock title="Find Me A Candidate!" >
<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("firstName").value,
document.getElementById("lastName").value,
document.getElementById("emailid").value
);
}
</script>
<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
<apex:param name="firstName" value="" />
<apex:param name="lastName" value="" />
<apex:param name="emailid" value="" />
</apex:actionFunction>
<table cellpadding="2" cellspacing="2">
<tr>
<td style="font-weight:bold;">First Name<br/>
<apex:inputText id="firstName" value="{!firstName}" >
<apex:actionsupport event="onkeyup" onbeforedomupdate="doSearch();"/>
</apex:inputText>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Last Name<br/>
<apex:inputText id="lastName" value="{!lastName}" >
<apex:actionsupport event="onkeyup" onbeforedomupdate="doSearch();"/>
</apex:inputText>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Email<br/>
<apex:inputText id="emailid" value="{!emailid}" >
<apex:actionsupport event="onkeyup" onbeforedomupdate="doSearch();"/>
</apex:inputText>
</td>
</tr>
</table>
</apex:pageBlock>
</td>
<td valign="top">
<apex:pageBlock id="results">
<apex:pageBlockTable value="{!candidates}" var="contact">
<apex:column >
<apex:facet name="header">
<apex:commandLink value="First Name" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="{!firstName}" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputlink value="/{!contact.Id}">
<apex:outputField value="{!contact.First_Name__c}"/>
</apex:outputlink>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Last Name" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="{!lastName}" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputlink value="/{!contact.Id}">
<apex:outputField value="{!contact.Last_Name__c}"/>
</apex:outputlink>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Email" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="{!emailid}" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputlink value="/{!contact.Id}">
<apex:outputField value="{!contact.Email__c}"/>
</apex:outputlink>
</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>
Are you getting any errors and if so what type of error?
Hi Sayasoni,
No I am not getting Error. It just the search is not working. I am not sure of any specific reason for this issue.
When I am entering any thing in the input boxes its not returning the output instead its displaying the same thing as before.
Hello, does the sample data display when the page loads?
I have a feeling that your problem is in the <apex:actionSupport> tag. In the Documentataion it states that if the action attribute is not set then the page will simply refresh. If that is strictly followed then your JavaScript is never getting called because there is no DOM update. I would probably try this:
<input type="text" id="firstName" onkeyup="doSearch();"/>
and see if it works. You also should not need the value attribute on the input tag since that is used for displaying a default value and you are not rerendering that section so the value will never be displayed, however the entered seach criteria should never go away as well. I believe that you should be able to use the <apex:inputText> tag as well as it does support the onkeyup event.
Let me know if this does not work and I will give you some more debugging device.
Hi Jake,
I have fixed issue. Actually the problem was in Apex Controller into the query.
anyways Many thanks for your valuable time.
---
Regards
Arish
So it actually is registering that as a DOM update? That is good to know!
Jake
Jake,
No it was not actually doing the Dom Update. I do have changed the input text code to
<input type="text" id="firstName" onkeyup="doSearch();"/>
Later I noticed that in the query there was a bug i made changes into that and its work great.
thanks
Arish
Cool, thanks for letting me know, I am glad you got it working!!
Hi Jake
I don't know if you are able to help with another query I have on my search page. The system has been invaluable to us, and I am now looking to make additional tweeks.
The code displays the members name and be default is is a click through to the Contact record. What I want is for it to just display the name and not be clickable.
The relevant section of the visualforce page is:
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Member" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="member" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!counselling_practice.Member__c}"/>
</apex:column>
No worries if its not something you can help with.
Regards
Justyn
Any advice on the controller and visualforce page code to use for checkboxes? I have everything else working perfectly apart from these particular field types.
Thanks
Justyn
I have never actually had the need to do that before. I have read where people have used images, basically if the cell is true display an image of a checked box if not display an unchecked box. I am fairly busy for the next couple of days, but if you can not get it, I can get something mocked up for you later in the week.
Hi Jake
My problem is more with getting the filter box to work. It happily displays a tick or not in the result section, but my empty field box for typing in the value for searching on does not like True, or False. The debug message says:
select name, ID, member__c, Counselling_Service__c, Therapeutic_Approach__c, fee_amount__c, Interests_Skills__c, Language__c, Referral_County__c, Practice_Area_Town__c, Practice_City_County__c, for_whom__c, gender__c, donations__c, negotiable__c, free_service__c from counselling_practice__c where name != null and currently_active__c = True and donations__c LIKE 'true%' order by Current_Year_Referrals__c asc limit 20
I am not 100% sure what you are asking, I think you copied and pasted the wrong thing as that is not a debug message. So you are saying that there is a problem when you type true or false into the search field?
Hi
You are right in that it isn't a debug message as such, but it is a something that is shown on the demo () to aid sorting problems. The problem is with the true or false in the search field. The relevant section from the search controller is:
if (!donations.equals('')) soql += ' and donations__c LIKE \''+String.escapeSingleQuotes(donations)+'%\'';
I'm assuming that this must be incorrect in some way?
Regards
Justyn
I see now, I know what debug message that you are talking about. Is donations__c a boolean field(checkbox) or a text field? True and False are Literal Constants but you are passing it as a string (i.e. 'true%') so if donations__c is a boolean it is not matching to the string, I would think. You could try this to check my conjecture:
soql += ' and donations__c = donations';
If donations__c is a string than that change will not work.
Another suggestion that I have is that you could download the force.com explorer from here:
http://wiki.developerforce.com/index.php/ForceExplorer
This will let you run a test query against the db if you copy and paste that debug code that you gave me above. You can manually tweak it till you get the result that you need and then if you post the valid soql query here, I can help you create some Apex to generate it.
Let me know if this helps!
HI Jake
Very helpful. You are correct in that the donations__c field is a checkbox. The code you mentioned presents the following message when I type true into the donations field search box :
select name, ID, member__c, Counselling_Service__c, Therapeutic_Approach__c, fee_amount__c, Interests_Skills__c, Language__c, Referral_County__c, Practice_Area_Town__c, Practice_City_County__c, for_whom__c, gender__c, donations__c, negotiable__c, free_service__c from counselling_practice__c where name != null and currently_active__c = True and donations__c = donations order by Current_Year_Referrals__c asc limit 20
Obviously the info is incorrect. If it replace it with True in Force Exlorer it presents the correct info:
select name, ID, member__c, Counselling_Service__c, Therapeutic_Approach__c, fee_amount__c, Interests_Skills__c, Language__c, Referral_County__c, Practice_Area_Town__c, Practice_City_County__c, for_whom__c, gender__c, donations__c, negotiable__c, free_service__c from counselling_practice__c where name != null and currently_active__c = True and donations__c = true order by Current_Year_Referrals__c asc limit 20
Is there an appropriate piece of code that work? On the one hand the ideal would be to have the search criteria on my visualforce page being a tick box rather than typing in True or False, and for it to then filter correctly. For now I'd be happy for the True ro False to work.
Thanks.
Justyn
Sorry, I was still half asleep when I wrote that.
Try this:
soql += ' and donations__c = ' + donations;
That should make the two queries match.
Hi Jake
That is perfect. Thanks.
You don't know the steps to make the data from the custom object publicly viewable on the visualforce page? I have the page added to my site.
No worries if not you have been really helpful already.
Regards
Justyn
I wrote a long drawn out answer on this then noticed the emphasis on publically and had to change tracks completely. :)
What you need to do is set up Force.com sites. It is on the setup page under Develop->Sites. Basically it will walk you through setting up a public facing URL, then you create a site and just add your VF page to it. I have not done it in awhile but from what I remember it is pretty straight forward. Let me know if you have questions.
Jake
Hi Jake
Thanks. I'd done that previously put the actual information for my custom object isn't displaying. The filters all seem to work in that there are no error messages, but the rows of info aren't displaying. I've also atted Counselling PRactice as Read in the Guest User License profile.
A strange one. I will have to search abit more.
Regards
Justyn
Hi All,
I am trying to do this on an account object, i have most of it working but i am trying to turn a multiselect picklist into a string.
How do i go about this? do i need to create a formula field in the object and use that or is there a simpler way
this is the code (the bit is at the bottom - it is the Buy & Sell currencies field)
and i'm getting this error
Error: ContactSearchController Compile Error: expecting a semi-colon, found '(' at line 57 column 14
Any help would be absoloutely amazing!!
First thing, lets fix your error.
String TEXT(Buy_Currencies__c) = Apexpages.currentPage().getParameters().get('Buy_Curr');
That is the line in question and I am not sure what you are trying to do. The Keyword String is declaring a new variable, the compiler is looking for an identifier next and finds TEXT so assumes that that is the identifier. Now it is looking for either an assignment operator (=) or the end of line character (;), but instead finds open parentheses. That is why it is throwing an error. I am not sure how to fix it, because I am not quite sure what you are trying to do with TEXT(Buy_Currencies__c) I have never seen a construction like that nor could I find reference to it in the Apex reference guide.
Anyway, I hope that helped, let me know what you are trying to do and I will try to help you get this resolved.
I used the TEXT(xxxx) because thats what i've used in formulas to pull a string from a multi select picklist.
I see, here is a blog post on a quick primer on how to use multi-select picklists:
http://salesforcesource.blogspot.com/2008/10/working-with-multiselect-picklists.html
http://hisrinu.wordpress.com/2011/05/30/custom-multi-select-picklist-field-in-visualforce/
Thanks. I've got that bit sorted.
Can anyone spot why the dynamic search part is not actually working (all the data is displaying ok on the page, just when you press the keys it is not performing the search.
Thanks for ANY help in advance
Apex Class
VF PAGE
THANK YOU to anyone that can help!!!!
Debugging this one could be kind of hard. The first thing I would check is that the query is being formed correctly. The easiest way to do that should be to put something like:
<apex:outputText value = "{!soql}" />
on your VF page.
You can then take and run that query in Force.com explorer (http://wiki.developerforce.com/page/ForceExplorer) and see if you are actually getting results. That will tell you if your problem is in forming the query, or in displaying the results.
To be honest i need a little more help than that, i've stripped the SQL statement out so it's only looking for one of the fields, and adjusted the VF page appropriately but still not getting any results.
I have used this code a couple of times in the past everything looks to be fine to me i just need a bit of help from someone that would be able to have a look at the code - just when typing in the fields the search is not happening
I tried adding the VF bit to the page that jake suggested but i am getting an error
I have two custom objects: rentrequests and items.
In rentrequest i have the item name , date required and which city as fields.
How can i use search code to search items ie using two objects?
HI,
I have a pageblocktable where I am able to search the records by name .
When I am trying to tranfer record. I could able to select the desired record.But problem comes when I try to search and try to transfer record.Somehow the desired records are not selected.
What could be the reason and how to avoid this..
I have a problem in using this search functionality.
So basically I have a pagelcoktable where I have search and transfer accounts functionality.
When I try to search and try to transfer accounts. It is getting the initial values in table
Can u help me in this regard about Why Iam getting such result.
Did either of you figure out why the code wasn't working? I have the same situation: it compiles fine, but when you type into the dynamic search boxes, nothing happens. I don't think the controller is calling the runSearch method properly but I'm not sure where it gets held up. Do either of you remember the solution you came up with?
Thank you!!