{"id":2470,"date":"2011-10-17T17:10:36","date_gmt":"2011-10-17T11:40:36","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=2470"},"modified":"2011-10-17T17:10:36","modified_gmt":"2011-10-17T11:40:36","slug":"salesforce-tutorial-create-simple-ajax-based-visualforce-page","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/webtech\/salesforce-tutorial-create-simple-ajax-based-visualforce-page\/","title":{"rendered":"Salesforce Tutorial &#8211; Create Simple Ajax based Visualforce page"},"content":{"rendered":"<p>Hello friends,<br \/>\nThis time i am going to create very simple AJAX based visual force page for the\u00a0beginners.<\/p>\n<p><strong>What is AJAX?<\/strong><\/p>\n<p>As many of you already know that the AJAX stands for the &#8220;<strong>Asynchronous javascript and XML<\/strong>&#8220;.<\/p>\n<blockquote><p>AJAX is the art of exchanging data between server and client without reloading the complete web page.<\/p><\/blockquote>\n<p><strong>Visualforce and AJAX<\/strong><\/p>\n<p>Visualforce has inbuilt support for the AJAX. using the attribute &#8220;<strong>rerender<\/strong>&#8221; we can specify that where the response should be rendered.<!--more--><\/p>\n<p><strong>Example:<\/strong><br \/>\nLets have an example to demonstrate that how simple AJAX works in visualforce.<br \/>\nCreate an APEX class with following code.<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\npublic class AjaxDemo {\n\n    private String currTime;\n    public String getCurrTime()\n    {\n        return currTime;\n    }\n    public void setCurrTime()\n    {\n        currTime = System.now().format('EEEE, MMMM d, yyyy - hh:mm:ss');\n    }\n}\n<\/pre>\n<p>As you can see in above Apex class, i have created method named &#8220;setCurrTime()&#8221; which will set the value of string variable. There is also one get method named as &#8220;getCurrTime()&#8221; which returns the value of that variable.<\/p>\n<p>On the basis of above Apex class lets create Visualforce page with below code.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;apex:page Controller=&quot;AjaxDemo&quot;&gt;\n&lt;apex:pageBlock Title=&quot;Ajax Sample&quot;&gt;\nHello &lt;b&gt; {!$User.FirstName}&lt;\/b&gt;.\n&lt;apex:form &gt;\n&lt;br \/&gt;&lt;br \/&gt;\n&lt;apex:commandbutton action=&quot;{!setCurrTime}&quot; rerender=&quot;ajaxresult&quot; value=&quot;Display Current Time&quot; \/&gt;\n\n&lt;\/apex:form&gt;\n&lt;\/apex:pageBlock&gt;\n\n&lt;apex:pageBlock title=&quot;AjaxData&quot;&gt;\n  &lt;apex:outputPanel id=&quot;ajaxresult&quot; layout=&quot;block&quot;&gt;\n    Result: {!CurrTime}\n  &lt;\/apex:outputPanel&gt;\n&lt;\/apex:pageBlock&gt;\n\n&lt;\/apex:page&gt;\n<\/pre>\n<p>There are few points to observe from above visualforce page<\/p>\n<ul>\n<li>Apex class earlier created is referenced using attribute &#8220;<strong>Controller<\/strong>&#8221; of &#8220;apex:page&#8221; tag.<\/li>\n<li>On &#8220;apex:commandbutton&#8221; we have specified that after clicking on button which method of the class should be called using attribute &#8220;<strong>action<\/strong>&#8220;.<\/li>\n<li>After the action completion of commandbutton which part of the apex page should gets refreshed is specified by attribute &#8220;<strong>rerender<\/strong>&#8220;.<\/li>\n<li>in outputpanel i have specified that which method should gets executed to get the result by simply giving the method name. In this case its <strong>{!CurrTime}<\/strong><\/li>\n<\/ul>\n<p>Output would look like:<\/p>\n<figure id=\"attachment_2471\" aria-describedby=\"caption-attachment-2471\" style=\"width: 372px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Simple-AJAX-demo-in-salesforce-using-visualforce.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2471\" title=\"Simple AJAX demo in salesforce using visualforce\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Simple-AJAX-demo-in-salesforce-using-visualforce.png?resize=372%2C286&#038;ssl=1\" alt=\"Simple AJAX demo in salesforce using visualforce\" width=\"372\" height=\"286\" \/><\/a><figcaption id=\"caption-attachment-2471\" class=\"wp-caption-text\">Simple AJAX demo in salesforce using visualforce<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Salesforce Tutorial &#8211; Step by step tutorial to create AJAX based application in visualforce page with Apex class<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[19],"tags":[337,331,336],"class_list":["post-2470","post","type-post","status-publish","format-standard","hentry","category-webtech","tag-apex","tag-salesforce","tag-visualforce"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3347,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/ajax-based-autocomplete-component-in-salesforce-using-jquery-ui-and-json\/","url_meta":{"origin":2470,"position":0},"title":"AutoComplete Component in Visualforce using JQueryUI","author":"Jitendra","date":"June 28, 2013","format":false,"excerpt":"In this tutorial, I am going to explain very Simple AJAX and JSON based Auto Complete component with the help of JQuery UI. First I am assuming that you already have Static Resource of named \"AutoCompleteWithModal\"\u009d. This Static resource has all images, CSS and JQuery library needed to implement this\u2026","rel":"","context":"In &quot;HTML&quot;","block_context":{"text":"HTML","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/webtech\/web\/"},"img":{"alt_text":"JQuery UI and JSON based AJAX AutoComplete Component in Salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/06\/JQuery-UI-and-JSON-based-AJAX-AutoComplete-Component-in-Salesforce.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/06\/JQuery-UI-and-JSON-based-AJAX-AutoComplete-Component-in-Salesforce.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2013\/06\/JQuery-UI-and-JSON-based-AJAX-AutoComplete-Component-in-Salesforce.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":3917,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/ajax-based-autocomplete-typeahead-directive-in-angularjs\/","url_meta":{"origin":2470,"position":1},"title":"Ajax based AutoComplete \/ TypeAhead Directive in AngularJS","author":"Jitendra","date":"July 15, 2014","format":false,"excerpt":"Previously we already discussed below Auto Complete components: Ajax Based Multiselect JQuery Autocomplete Control in ASP.Net AutoComplete Component in Visualforce using JQueryUI In this article, we will be creating TypeAhead Directive (Auto Complete) again in Salesforce However this time we will use AngularJs. Why we are using AngularJS ? We\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"TypeAhead Demo using AngularJs","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/07\/TypeAhead-Demo-using-AngularJs.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/07\/TypeAhead-Demo-using-AngularJs.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/07\/TypeAhead-Demo-using-AngularJs.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2014\/07\/TypeAhead-Demo-using-AngularJs.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":4394,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/create-and-update-records-using-javascript-button-in-salesforce-ajax-toolkit\/","url_meta":{"origin":2470,"position":2},"title":"Create and update records using Javascript button in Salesforce- Ajax Toolkit","author":"Jitendra","date":"April 21, 2015","format":false,"excerpt":"On this blog we have already seen \"how to use Ajax Toolkit to mass update records\" without writing any Apex code. In this article as well, we will use Ajax Toolkit to add custom button in Account page layout and update record. There are endless possibilities and use-cases where this\u2026","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Update Record using Javascript","src":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Update-Record-using-Javascript.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Update-Record-using-Javascript.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Update-Record-using-Javascript.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.jitendrazaa.com\/blog\/wp-content\/uploads\/2015\/04\/Update-Record-using-Javascript.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3185,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-question-part-14\/","url_meta":{"origin":2470,"position":3},"title":"Salesforce Interview Question \u2013 Part 14","author":"Jitendra","date":"February 28, 2013","format":false,"excerpt":"131. What will happen if you try to update record in After Trigger Context? Ans : You will get an error saying \"record is Read only\". 132. Let's say we have to update the same record in After Trigger context. Is there any way or workaround? Ans : If we\u2026","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4618,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/most-frequently-used-code-snippets-for-salesforce-developers-faq-part-21\/","url_meta":{"origin":2470,"position":4},"title":"Salesforce Developers interview questions &#8211; Most commonly used code snippets &#8211; part 21","author":"Jitendra","date":"July 7, 2015","format":false,"excerpt":"Salesforce interview questions - Most frequently used Apex and visualforce code used by Salesforce developers like \"How to query and abort scheduled job using Apex\", \"Defining VF page as HTML5\", \"Visualforce page as JSON\" , \"Handling colon in element Id for Jquery\" , \"Chatter using Apex\" and many more.","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2643,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/passing-parameter-in-actionfunction-in-visualforce\/","url_meta":{"origin":2470,"position":5},"title":"Passing multiple Parameters in ActionFunction in Visualforce","author":"Jitendra","date":"January 15, 2012","format":false,"excerpt":"Example and Source code of multiple Parameters Parameter in ActionFunction in Visualforce - Salesforce","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Passing Parameter in ActionFunction in Visualforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2012\/01\/Passing-Parameter-in-ActionFunction-in-Visualforce.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=2470"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2470\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=2470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=2470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=2470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}