{"id":7,"date":"2013-06-05T09:01:45","date_gmt":"2013-06-05T09:01:45","guid":{"rendered":"http:\/\/www.greytrix.com\/blogs\/salesforce\/?p=7"},"modified":"2018-08-22T05:50:10","modified_gmt":"2018-08-22T05:50:10","slug":"calling-soql-query-from-javascript-for-validation-of-account-name-in-salesforce","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2013\/06\/05\/calling-soql-query-from-javascript-for-validation-of-account-name-in-salesforce\/","title":{"rendered":"Calling SOQL Query from JavaScript for validation of Account Name in Salesforce"},"content":{"rendered":"<p style=\"text-align: justify;\">Recently, we had a requirement from one of our clients, wherein they wanted a page where user had to enter the Account Name. We were required to validate that account name and then do further processing.<\/p>\n<p style=\"text-align: justify;\">In below code snippets, we are checking if the Account name entered by the user is valid by querying on Account table\/object directly in the JavaScript code. To simplify the code, we have used the variable AccountName in JavaScript to specify the account name.<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&lt;snip&gt;<br \/>\n<span style=\"color: #000000;\"> <em>&lt;apex:page &gt;<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em>&lt;script language=&#8221;JavaScript1.2&#8243; src=&#8221;\/js\/functions.js&#8221;&gt;&lt;\/script&gt;<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em>&lt;script src=&#8221;\/soap\/ajax\/9.0\/connection.js&#8221; type=&#8221;text\/javascript&#8221;&gt;&lt;\/script&gt;<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em>&lt;script id=&#8221;clientEventHandlersJS&#8221; language=&#8221;javascript&#8221;&gt;<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> function CallSOQL() <\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> {<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> sforce.connection.sessionId = &#8216;{!$Api.Session_ID}&#8217;;<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> try<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> {<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> alert(&#8216;Select Name, Id From Account ORDER BY Name&#8217;);<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> var AccountName=&#8221; TEST ACCOUNT&#8221;;<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> var qr = sforce.connection.query(&#8220;SELECT id,name FROM Account where Name='&#8221;+ AccountName +&#8221;&#8216;&#8221;);<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> var records = qr.getArray(&#8220;records&#8221;);<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> alert(&#8216;qr &#8216;+qr);<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> }<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> catch (error)<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> {<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> alert(error.faultstring);<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> }<\/em><\/span><\/p>\n<p><span style=\"color: #000000;\"><em>if (qr.size == 0)<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> {<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> alert(&#8220;No Record found.&#8221;);<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> }<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> else<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> {<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> for (var i=0;i&lt;qr.records.length;i++)<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> {<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> alert(qr.records[i].Name);<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em> }<\/em><\/span><\/p>\n<p><span style=\"color: #000000;\"><em> }<\/em><\/span><\/p>\n<p><span style=\"color: #000000;\"><em>}<\/em><\/span><br \/>\n<span style=\"color: #000000;\"> <em>&lt;\/script&gt;<\/em><\/span><\/p>\n<p><span style=\"color: #000000;\"><em>&lt;input type=&#8221;button&#8221; onclick=&#8221;CallSOQL();&#8221; value=&#8221;Call SOQL Query&#8221;\/&gt;&lt;\/apex:page&gt;<\/em><\/span><\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&lt;snip&gt;<\/p>\n<p style=\"text-align: justify;\">By using the above given code, you can query on any object or custom object of Salesforce without writing code on <span style=\"color: #000000;\">controller side.<\/span><\/p>\n<blockquote>\n<p style=\"text-align: justify;\">Greytrix offers <a href=\"https:\/\/www.greytrix.com\/product\/sage-300-erp\/gumu-300-salesforce-integration\">GUMU&#x2122; for Salesforce &#8211; Sage 300 (Accpac) Integration<\/a> a best of breed solution for organizations to enhance their customer interaction.<\/p>\n<\/blockquote>\n<p><span style=\"font-size: Medium;\"><strong>About Us<\/strong><\/span><br \/>\n<a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a>\u00a0as a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners across the globe. We offers Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that requires apex code incorporation into the Salesforce platform.<\/p>\n<p><a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a>\u00a0has some unique solutions for Cloud CRM such as Salesforce integration with\u00a0<a href=\"https:\/\/www.greytrix.com\/product\/sage-x3\/gumu-x3-salesforce-integration\">Sage Enterprise Management (Sage X3<\/a>),\u00a0Sage Intacct, <a href=\"https:\/\/www.greytrix.com\/product\/sage-100-erp\/gumu-100-salesforce-integration\">Sage 100\u00a0<\/a>and\u00a0<a href=\"https:\/\/www.greytrix.com\/product\/sage-300-erp\/gumu-300-salesforce-integration\">Sage 300 (Sage Accpac)<\/a>. We also offer best-in-class Cloud CRM\u00a0<a href=\"https:\/\/www.greytrix.com\/product\/crm-development\/salesforce-com\">Salesforce customization and development services<\/a> along with services such as Salesforce <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/data-migration-services\">Data Migration<\/a>, <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/integrated-application-development\">Integrated App development<\/a>, <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/custom-development\">Custom App development<\/a> and <a href=\"https:\/\/www.greytrix.com\/product\/professional-services\/maintenance-support\">Technical Support<\/a> to business partners and end users.<\/p>\n<p>Greytrix GUMU&#x2122; integration for Sage ERP \u2013 Salesforce is a 5-star app listed on <a href=\"https:\/\/appexchange.salesforce.com\/listingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noopener\">Salesforce AppExchange<\/a>.<\/p>\n<p>For more information, please contact us at\u00a0<a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, we had a requirement from one of our clients, wherein they wanted a page where user had to enter the Account Name. We were required to validate that account name and then do further processing. In below code snippets, we are checking if the Account name entered by the user is valid by querying\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2013\/06\/05\/calling-soql-query-from-javascript-for-validation-of-account-name-in-salesforce\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[5,68,194,290,397,403,405,473],"class_list":["post-7","post","type-post","status-publish","format-standard","hentry","category-gumu-salesforce","tag-account-name","tag-custom-object","tag-javascript","tag-query","tag-salesforce-integration","tag-salesforce-integration-with-sage-300-erp","tag-salesforce-integration-with-sage-x3","tag-soql-query"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/7","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/comments?post=7"}],"version-history":[{"count":8,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/7\/revisions"}],"predecessor-version":[{"id":3960,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/7\/revisions\/3960"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}