Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the user-registration domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php on line 6121 Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hashone domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php on line 6121 Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896 Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896 Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896 Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896 Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896 Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896 Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896 Warning: Cannot modify header information - headers already sent by (output started at /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/functions.php:6121) in /customers/c/c/d/ccloudonline.nl/httpd.www/wp-includes/rest-api/class-wp-rest-server.php on line 1896 {"id":648,"date":"2017-03-11T18:21:24","date_gmt":"2017-03-11T18:21:24","guid":{"rendered":"http:\/\/ccloudonline.nl\/a-homepage-section\/?p=648"},"modified":"2020-01-12T14:25:26","modified_gmt":"2020-01-12T14:25:26","slug":"dynamic-account-search","status":"publish","type":"post","link":"http:\/\/ccloudonline.nl\/?p=648","title":{"rendered":"Dynamic Account Search"},"content":{"rendered":"

D<\/span>ynamic Account Search<\/h3>\n

I had a business requierment that was involving coding a controller in combination wiht a Visualforce page.
\nThe idea was to enable users to dynamically\u00a0search for accounts. Looking for some ideas I found a really nice example from Jeff Douglas, you can find it here<\/a>. So I took this structure and build\u00a0my own page. The most interesting part of this code is the fact that you don’t event need to click a “search” button to start retriving results. As nice as that can be there are other things that I really like about this code. The simplicity and efficiency\u00a0of this code are really outstanding, that is why I want to share this with you, all credit goes to Jeff of course … I’m just a messenger.<\/p>\n

This is the controller:<\/p>\n

[code lang=\"php\"]\n\/\/AccountSearch controller \n\npublic with sharing class AccountSearch {\n\n  private String soql {get;set;}\n  public List&amp;amp;amp;amp;amp;amp;amp;lt;Account&amp;amp;amp;amp;amp;amp;amp;gt; accounts {get;set;}\n\n  public String sortDir\n  {\n    get  {\n         if (sortDir == null)\n           {\n             sortDir = 'asc';\n           }\n             return sortDir;\n         }\n    set;\n  }\n\n  public String sortField\n  {\n    get  {\n         if (sortField == null)\n           {\n             sortField = 'name';\n           }\n             return sortField;\n         }\n    set;\n  }\n\n  public String debugSoql {\n    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }\n    set;\n  }\n\n  public AccountSearch()\n  {\n    soql = 'select name, industry, shippingCountry from account where name != null';\n    runQuery();\n  }\n\n  public void toggleSort()\n  {\n    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';\n\n    runQuery();\n  }\n\n  public void runQuery()\n  {\n\n    try {\n      accounts = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');\n      if(accounts.isEmpty())\n      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Sorry, there are no results on your search criteria.')); \n\n    } catch (Exception e) {\n      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Something went wrong with your search!'));\n    }\n\n  }\n\n  public PageReference runSearch()\n  {\n\n    String name = Apexpages.currentPage().getParameters().get('name');\n    String industry = Apexpages.currentPage().getParameters().get('industry');\n    String shippingCountry =Apexpages.currentPage().getParameters().get('shippingCountry');\n\n    soql = 'select name, industry, shippingCountry from account where name != null';\n    if (!name.equals(''))\n      soql += ' and name LIKE \\''+String.escapeSingleQuotes(name)+'%\\'';\n    if (!industry.equals(''))\n    soql += ' and name LIKE \\''+String.escapeSingleQuotes(industry)+'%\\'';\n    if (!shippingCountry.equals(''))\n    soql += ' and shippingCountry LIKE \\''+String.escapeSingleQuotes(shippingCountry)+'%\\'';\n\n    runQuery();\n\n    return null;\n  }  \n\n}\n[\/code]<\/pre>\n

I did some changes to fix a few issues I had with this controller and now works like a charm. I like the way Jeff used properties to get the SOQL query sorted, real nice touch.<\/p>\n

Here you can find the Visualforce page for this controller:<\/p>\n

[code lang=\"java\"]\n\/\/AccountSearch visualforce\n&amp;amp;amp;amp;amp;amp;amp;lt;apex:page controller="AccountSearch" sidebar="false" showHeader="false"&amp;amp;amp;amp;amp;amp;amp;gt;\n\n  &amp;amp;amp;amp;amp;amp;amp;lt;apex:form &amp;amp;amp;amp;amp;amp;amp;gt;\n  &amp;amp;amp;amp;amp;amp;amp;lt;apex:pageMessages id="errors" \/&amp;amp;amp;amp;amp;amp;amp;gt;\n\n  &amp;amp;amp;amp;amp;amp;amp;lt;apex:pageBlock title="Account Search" mode="edit"&amp;amp;amp;amp;amp;amp;amp;gt;\n\n  &amp;amp;amp;amp;amp;amp;amp;lt;table width="100%" border="0"&amp;amp;amp;amp;amp;amp;amp;gt;\n  &amp;amp;amp;amp;amp;amp;amp;lt;tr&amp;amp;amp;amp;amp;amp;amp;gt;\n    &amp;amp;amp;amp;amp;amp;amp;lt;td width="200" valign="top"&amp;amp;amp;amp;amp;amp;amp;gt;\n\n      &amp;amp;amp;amp;amp;amp;amp;lt;apex:pageBlock title="" mode="edit" id="criteria"&amp;amp;amp;amp;amp;amp;amp;gt;\n\n      &amp;amp;amp;amp;amp;amp;amp;lt;script type="text\/javascript"&amp;amp;amp;amp;amp;amp;amp;gt;\n      function doSearch() {\n        searchServer(\n          document.getElementById("name").value,\n          document.getElementById("industry").value,\n          document.getElementById("shippingCountry").value);\n      }\n      &amp;amp;amp;amp;amp;amp;amp;lt;\/script&amp;amp;amp;amp;amp;amp;amp;gt;\n\n      &amp;amp;amp;amp;amp;amp;amp;lt;apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors"&amp;amp;amp;amp;amp;amp;amp;gt;\n          &amp;amp;amp;amp;amp;amp;amp;lt;apex:param name="name" value="" \/&amp;amp;amp;amp;amp;amp;amp;gt;\n          &amp;amp;amp;amp;amp;amp;amp;lt;apex:param name="industry" value="" \/&amp;amp;amp;amp;amp;amp;amp;gt;\n          &amp;amp;amp;amp;amp;amp;amp;lt;apex:param name="shippingCountry" value="" \/&amp;amp;amp;amp;amp;amp;amp;gt;\n\n      &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:actionFunction&amp;amp;amp;amp;amp;amp;amp;gt;\n\n      &amp;amp;amp;amp;amp;amp;amp;lt;table cellpadding="2" cellspacing="2"&amp;amp;amp;amp;amp;amp;amp;gt;\n\n      &amp;amp;amp;amp;amp;amp;amp;lt;tr&amp;amp;amp;amp;amp;amp;amp;gt;\n        &amp;amp;amp;amp;amp;amp;amp;lt;td style="font-weight:bold;"&amp;amp;amp;amp;amp;amp;amp;gt;Name&amp;amp;amp;amp;amp;amp;amp;lt;br\/&amp;amp;amp;amp;amp;amp;amp;gt;\n        &amp;amp;amp;amp;amp;amp;amp;lt;input type="text" id="name" onkeyup="doSearch();"\/&amp;amp;amp;amp;amp;amp;amp;gt;\n        &amp;amp;amp;amp;amp;amp;amp;lt;\/td&amp;amp;amp;amp;amp;amp;amp;gt;\n      &amp;amp;amp;amp;amp;amp;amp;lt;\/tr&amp;amp;amp;amp;amp;amp;amp;gt;\n      &amp;amp;amp;amp;amp;amp;amp;lt;tr&amp;amp;amp;amp;amp;amp;amp;gt;\n        &amp;amp;amp;amp;amp;amp;amp;lt;td style="font-weight:bold;"&amp;amp;amp;amp;amp;amp;amp;gt;Industry&amp;amp;amp;amp;amp;amp;amp;lt;br\/&amp;amp;amp;amp;amp;amp;amp;gt;\n        &amp;amp;amp;amp;amp;amp;amp;lt;input type="text" id="industry" onkeyup="doSearch();"\/&amp;amp;amp;amp;amp;amp;amp;gt;\n        &amp;amp;amp;amp;amp;amp;amp;lt;\/td&amp;amp;amp;amp;amp;amp;amp;gt;\n      &amp;amp;amp;amp;amp;amp;amp;lt;\/tr&amp;amp;amp;amp;amp;amp;amp;gt;\n      &amp;amp;amp;amp;amp;amp;amp;lt;tr&amp;amp;amp;amp;amp;amp;amp;gt;\n        &amp;amp;amp;amp;amp;amp;amp;lt;td style="font-weight:bold;"&amp;amp;amp;amp;amp;amp;amp;gt;Shipping Country&amp;amp;amp;amp;amp;amp;amp;lt;br\/&amp;amp;amp;amp;amp;amp;amp;gt;\n        &amp;amp;amp;amp;amp;amp;amp;lt;input type="text" id="shippingCountry" onkeyup="doSearch();"\/&amp;amp;amp;amp;amp;amp;amp;gt;\n        &amp;amp;amp;amp;amp;amp;amp;lt;\/td&amp;amp;amp;amp;amp;amp;amp;gt;\n      &amp;amp;amp;amp;amp;amp;amp;lt;\/tr&amp;amp;amp;amp;amp;amp;amp;gt;\n   &amp;amp;amp;amp;amp;amp;amp;lt;\/table&amp;amp;amp;amp;amp;amp;amp;gt;\n\n      &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:pageBlock&amp;amp;amp;amp;amp;amp;amp;gt;\n\n    &amp;amp;amp;amp;amp;amp;amp;lt;\/td&amp;amp;amp;amp;amp;amp;amp;gt;\n    &amp;amp;amp;amp;amp;amp;amp;lt;td valign="top"&amp;amp;amp;amp;amp;amp;amp;gt;\n\n    &amp;amp;amp;amp;amp;amp;amp;lt;apex:pageBlock mode="edit" id="results"&amp;amp;amp;amp;amp;amp;amp;gt;\n\n        &amp;amp;amp;amp;amp;amp;amp;lt;apex:pageBlockTable value="{!accounts}" var="account"&amp;amp;amp;amp;amp;amp;amp;gt;\n\n            &amp;amp;amp;amp;amp;amp;amp;lt;apex:column &amp;amp;amp;amp;amp;amp;amp;gt;\n                &amp;amp;amp;amp;amp;amp;amp;lt;apex:facet name="header"&amp;amp;amp;amp;amp;amp;amp;gt;\n                    &amp;amp;amp;amp;amp;amp;amp;lt;apex:commandLink value="Name" action="{!toggleSort}" rerender="results,debug"&amp;amp;amp;amp;amp;amp;amp;gt;\n                        &amp;amp;amp;amp;amp;amp;amp;lt;apex:param name="sortField" value="name" assignTo="{!sortField}"\/&amp;amp;amp;amp;amp;amp;amp;gt;\n                    &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:commandLink&amp;amp;amp;amp;amp;amp;amp;gt;\n                &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:facet&amp;amp;amp;amp;amp;amp;amp;gt;\n                &amp;amp;amp;amp;amp;amp;amp;lt;apex:outputField value="{!account.name}"\/&amp;amp;amp;amp;amp;amp;amp;gt;\n            &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:column&amp;amp;amp;amp;amp;amp;amp;gt;\n\n            &amp;amp;amp;amp;amp;amp;amp;lt;apex:column &amp;amp;amp;amp;amp;amp;amp;gt;\n                &amp;amp;amp;amp;amp;amp;amp;lt;apex:facet name="header"&amp;amp;amp;amp;amp;amp;amp;gt;\n                    &amp;amp;amp;amp;amp;amp;amp;lt;apex:commandLink value="Industry" action="{!toggleSort}" rerender="results,debug"&amp;amp;amp;amp;amp;amp;amp;gt;\n                        &amp;amp;amp;amp;amp;amp;amp;lt;apex:param name="sortField" value="Industry" assignTo="{!sortField}"\/&amp;amp;amp;amp;amp;amp;amp;gt;\n                    &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:commandLink&amp;amp;amp;amp;amp;amp;amp;gt;\n                &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:facet&amp;amp;amp;amp;amp;amp;amp;gt;\n                &amp;amp;amp;amp;amp;amp;amp;lt;apex:outputField value="{!account.industry}"\/&amp;amp;amp;amp;amp;amp;amp;gt;\n            &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:column&amp;amp;amp;amp;amp;amp;amp;gt;\n\n           &amp;amp;amp;amp;amp;amp;amp;lt;apex:column &amp;amp;amp;amp;amp;amp;amp;gt;\n                &amp;amp;amp;amp;amp;amp;amp;lt;apex:facet name="header"&amp;amp;amp;amp;amp;amp;amp;gt;\n                    &amp;amp;amp;amp;amp;amp;amp;lt;apex:commandLink value="ShippingCountry" action="{!toggleSort}" rerender="results,debug"&amp;amp;amp;amp;amp;amp;amp;gt;\n                        &amp;amp;amp;amp;amp;amp;amp;lt;apex:param name="sortField" value="shippingCountry" assignTo="{!sortField}"\/&amp;amp;amp;amp;amp;amp;amp;gt;\n                    &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:commandLink&amp;amp;amp;amp;amp;amp;amp;gt;\n                &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:facet&amp;amp;amp;amp;amp;amp;amp;gt;\n                &amp;amp;amp;amp;amp;amp;amp;lt;apex:outputField value="{!account.shippingCountry}"\/&amp;amp;amp;amp;amp;amp;amp;gt;\n            &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:column&amp;amp;amp;amp;amp;amp;amp;gt;\n       &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:pageBlockTable&amp;amp;amp;amp;amp;amp;amp;gt;\n    &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:pageBlock&amp;amp;amp;amp;amp;amp;amp;gt;\n\n    &amp;amp;amp;amp;amp;amp;amp;lt;\/td&amp;amp;amp;amp;amp;amp;amp;gt;\n  &amp;amp;amp;amp;amp;amp;amp;lt;\/tr&amp;amp;amp;amp;amp;amp;amp;gt;\n  &amp;amp;amp;amp;amp;amp;amp;lt;\/table&amp;amp;amp;amp;amp;amp;amp;gt;\n\n  &amp;amp;amp;amp;amp;amp;amp;lt;apex:pageBlock title="Extra Information" id="debug"&amp;amp;amp;amp;amp;amp;amp;gt;\n      &amp;amp;amp;amp;amp;amp;amp;lt;apex:outputText value="Please refer to this information if you can't find your account" \/&amp;amp;amp;amp;amp;amp;amp;gt;\n  &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:pageBlock&amp;amp;amp;amp;amp;amp;amp;gt;    \n\n  &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:pageBlock&amp;amp;amp;amp;amp;amp;amp;gt;\n\n  &amp;amp;amp;amp;amp;amp;amp;lt;\/apex:form&amp;amp;amp;amp;amp;amp;amp;gt;\n\n&amp;amp;amp;amp;amp;amp;amp;lt;\/apex:page&amp;amp;amp;amp;amp;amp;amp;gt;\n\n[\/code]<\/pre>\n

Real nice and simple…<\/p>\n","protected":false},"excerpt":{"rendered":"

Dynamic Account Search I had a business requierment that was involving coding a controller in combination wiht a Visualforce page. The idea was to enable users to dynamically\u00a0search for accounts. Looking for some ideas I found a really nice example from Jeff Douglas, you can find it here. So I took this structure and build\u00a0my […]<\/p>\n","protected":false},"author":1,"featured_media":650,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-648","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centerblog"],"_links":{"self":[{"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/posts\/648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=648"}],"version-history":[{"count":37,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/posts\/648\/revisions"}],"predecessor-version":[{"id":2841,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/posts\/648\/revisions\/2841"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=\/wp\/v2\/media\/650"}],"wp:attachment":[{"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=648"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ccloudonline.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}