{"id":552,"date":"2014-05-27T05:55:23","date_gmt":"2014-05-27T05:55:23","guid":{"rendered":"http:\/\/www.greytrix.com\/blogs\/salesforce\/?p=552"},"modified":"2024-08-08T05:32:46","modified_gmt":"2024-08-08T05:32:46","slug":"prevent-page-redirection-on-apex-command-button-through-javascript","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2014\/05\/27\/prevent-page-redirection-on-apex-command-button-through-javascript\/","title":{"rendered":"Prevent page redirection on Apex Command Button through JavaScript"},"content":{"rendered":"<p>We had a requirement to add client side validation on Apex Command Button but the page was getting redirected after successful validation.<\/p>\n<p><a href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2014\/05\/Img001.jpg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-560\" src=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2014\/05\/Img001.jpg\" alt=\"Img001\" width=\"416\" height=\"82\" \/><\/a><\/p>\n<p>So, we tried the following JavaScript code to prevent the page redirection but it didn\u2019t work.<a href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2014\/05\/ApexCode1.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-553\" src=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2014\/05\/ApexCode1.png\" alt=\"ApexCode1\" width=\"463\" height=\"216\" \/><\/a>We then found a solution to stop redirection by adding the following code at the Command Click Event. The code is as shown below:<a href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2014\/05\/ApexCode21.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-557\" src=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2014\/05\/ApexCode21.png\" alt=\"ApexCode2\" width=\"522\" height=\"210\" \/><\/a><\/p>\n<p>Using the above code, we were able to successfully prevent the page redirection on Apex Command button.<\/p>\n<p><span style=\"font-size: Medium;\"><strong>About Us<\/strong><\/span><br \/>\n<a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a> as 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> has some unique solutions for Cloud CRM such as Salesforce integration with <a href=\"https:\/\/www.greytrix.com\/product\/sage-x3\/gumu-x3-salesforce-integration\">Sage Enterprise Management (Sage X3<\/a>), Sage Intacct, <a href=\"https:\/\/www.greytrix.com\/product\/sage-100-erp\/gumu-100-salesforce-integration\">Sage 100 <\/a>and <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 <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 <a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n<p><strong><span style=\"font-size: Medium;\">Related Posts<\/span><\/strong><\/p>\n<ul>\n<li><a title=\"Testing Deliverability of an Email sent from Salesforce\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2014\/05\/22\/testing-deliverability-of-an-email-sent-from-salesforce\/\" target=\"_blank\" rel=\"noopener\">Testing deliverability of an Email sent from Salesforce<\/a><\/li>\n<li><a title=\"Prevent Salesforce Emails from ending up in Spam Folder\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2014\/05\/21\/prevent-salesforce-emails-from-ending-up-in-spam-folder\/\" target=\"_blank\" rel=\"noopener\">Prevent Salesforce Emails from ending up in Spam Folder<\/a><\/li>\n<li><a title=\"One link direct login to Salesforce\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2014\/04\/21\/one-link-direct-login-to-salesforce\/\" target=\"_blank\" rel=\"noopener\">One link direct login to Salesforce<\/a><\/li>\n<li><a title=\"Removing footer in Salesforce Reports\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2014\/04\/01\/removing-footer-in-salesforce-reports\/\" target=\"_blank\" rel=\"noopener\">Removing footer in Salesforce Reports<\/a><\/li>\n<li><a title=\"Calculating the time taken between two dates\" href=\"http:\/\/www.greytrix.com\/blogs\/salesforce\/2014\/03\/29\/calculating-the-time-taken-between-two-dates\/\" target=\"_blank\" rel=\"noopener\">Calculating the time taken between two dates<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>We had a requirement to add client side validation on Apex Command Button but the page was getting redirected after successful validation. So, we tried the following JavaScript code to prevent the page redirection but it didn\u2019t work.We then found a solution to stop redirection by adding the following code at the Command Click Event.\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2014\/05\/27\/prevent-page-redirection-on-apex-command-button-through-javascript\/\">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":[3],"tags":[13,585,586,48,194],"class_list":["post-552","post","type-post","status-publish","format-standard","hentry","category-salesforce-srv","tag-apex","tag-apex-command-button","tag-apex-page-redirection","tag-command-button","tag-javascript"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/552","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=552"}],"version-history":[{"count":1,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/552\/revisions"}],"predecessor-version":[{"id":4020,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/552\/revisions\/4020"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}