{"id":7224,"date":"2014-05-31T19:38:03","date_gmt":"2014-05-31T19:38:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/31\/salesforce-javascript-ajax-trying-to-use-a-parameters-collection-of-common-programming-errors-2\/"},"modified":"2014-05-31T19:38:03","modified_gmt":"2014-05-31T19:38:03","slug":"salesforce-javascript-ajax-trying-to-use-a-parameters-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/31\/salesforce-javascript-ajax-trying-to-use-a-parameters-collection-of-common-programming-errors-2\/","title":{"rendered":"Salesforce &amp; Javascript \/ Ajax &#8211; Trying to use a parameters-Collection of common programming errors"},"content":{"rendered":"<p><em>Following this post :<\/em><\/p>\n<p>Define Apex controller in javascript home component<\/p>\n<p>I tried to improved it, because the limit of Salesforce for an SOQL request is <strong>50k records<\/strong>.<\/p>\n<p>The <strong>Code_Postal__c<\/strong> object can have more than 50k of records.<\/p>\n<p>I saw that we can parse item in javascript (i&#8217;m pretty bad with this language). The idea is to make a dynamic call of my controller when the user will start typing the postal code ( id of the field = #acc18zip ). But i got an error with my item list, so i came back to use my string but it didn&#8217;t work. When i tried to find the error with the chrome console or firebug i saw this error into my console :<\/p>\n<pre><code>Uncaught SyntaxError: Unexpected end of input \n<\/code><\/pre>\n<p>and when i start typing a postal code:<\/p>\n<pre><code>event.returnValue is deprecated. Please use the standard event.preventDefault() instead. \n<\/code><\/pre>\n<p>My updated controller is this one :<\/p>\n<pre><code>global class cpSearch2{ \n    webService static String searchCP() {\n        String pickValues='';\n        for(Code_Postal__c cp : [Select Commune__c, Code_Postal__c from Code_Postal__c ]){\n               pickValues = pickValues +cp.Code_Postal__c+ ' - ' + cp.Commune__c+'+';\n        }\n        return pickValues;\n    }\n\n    webService static string searchCP2(string searchTerm) {\n        String pickValues='';\n        for(Code_Postal__c cp : [Select Commune__c, Code_Postal__c from Code_Postal__c where Code_Postal__c LIKE :searchTerm]){\n                pickValues = pickValues +cp.Code_Postal__c+ ' - ' + cp.Commune__c+'+';\n        }\n        return pickValues;\n    }\n\n    \/*\n    Function with list of object\n    webService static list searchCP2(string searchTerm) {\n        list matchingCP = new list();\n        for(Code_Postal__c cp : [Select Commune__c, Code_Postal__c from Code_Postal__c where Code_Postal__c LIKE :searchTerm]){\n               matchingCP.add(cp);\n        }\n        return matchingCP;\n    }*\/\n}\n<\/code><\/pre>\n<p>and the updated javascript is :<\/p>\n<pre><code>\n\n\n\n\n\n\nvar url = document.URL;\nif(url.indexOf('001')!=-1)    \n{        \n        var sid = document.cookie.match(' sid=([^;]*)')[1];        \n        sforce.debug.trace=true;        \n        sforce.connection.sessionId = sid;        ;\n        var stages;\n        var cpObjects;\n        var queryTerm;\n        $ = jQuery.noConflict();       \n        $(function()             \n            {                             \n                $( \"#acc18zip\" ).autocomplete({\n                       source:function( request, response ) {\n                        queryTerm = request.term;\n                        stages = sforce.apex.execute(\"cpSearch2\", \"searchCP2\", {queryTerm,function(result, event)});\n                        if(event.type == 'exception') {\n                            alert(event.message);\n                        } else {\n                            cpObjects = stages.toString().split(\"+\");\n                            response(cpObjects);\n                        }                       \n                       },\n                        focus: function( event, ui ) {\n                            $(\"#acc18zip\").val(selectedArray[0]);\n                            $(\"#acc18city\").val(selectedArray[1]);\n                            return false;\n                        },\n                       select: function( event, ui ) {\n                       console.log(ui.item); \n                       selectedArray = ui.item.split(\" - \");\n                       $(\"#acc18zip\").val(selectedArray[0]);\n                       $(\"#acc18city\").val(selectedArray[1]);\n                       return false;\n                        }\n                });     \n            });    \n}\n\n<\/code><\/pre>\n<p>Trying to follow this :<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"czgsOjqDaO\"><p><a href=\"https:\/\/jqueryui.com\/autocomplete\/\">Autocomplete<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Autocomplete&#8221; &#8212; jQuery UI\" src=\"https:\/\/jqueryui.com\/autocomplete\/embed\/#?secret=w8FDC7XerK#?secret=czgsOjqDaO\" data-secret=\"czgsOjqDaO\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following this post : Define Apex controller in javascript home component I tried to improved it, because the limit of Salesforce for an SOQL request is 50k records. The Code_Postal__c object can have more than 50k of records. I saw that we can parse item in javascript (i&#8217;m pretty bad with this language). The idea [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7224","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7224"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7224\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}