{"id":51536,"date":"2016-06-10T15:55:14","date_gmt":"2016-06-10T15:55:14","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=51536"},"modified":"2021-07-16T12:28:29","modified_gmt":"2021-07-16T12:28:29","slug":"how-to-get-current-page-url-from-apex-code","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/","title":{"rendered":"How To Get Current Page URL from Apex code"},"content":{"rendered":"\n<p>In this post, I am going to share the information <strong>How To Get Current Page URL from Apex code <\/strong>in Salesforce. So we need to use Apexpages.currentPage() methods.<\/p>\n\n\n\n<div class=\"wk-index-wrap\"><h3 class=\"index-title\">\u00a0Get Current Page URL<\/h3><\/div><div class=\"margin-bottom-50\">\n<p><strong>&#8216;getHeaders()&#8217;<\/strong> : It return a map of the request headers.where the key string contains the name of the header, and the value string contains the value of the header.<br>After that get the \u2018Host\u2019 key value from that map<\/p>\n\n\n\n<p><strong>&#8216;getUrl()&#8217;<\/strong> : It returns the relative URL associated with the PageReference when it was originally defined, including any query string parameters and anchors.<\/p>\n\n\n\n<p><strong>Apex Code<\/strong> :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:java\">public with sharing class pageurlclass{\n\n         \/**\n         * Webkul Software.\n         *\n         * @category  Webkul\n         * @author    Webkul\n         * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\n         * @license   https:\/\/store.webkul.com\/license.html\n         *\/\n\n    public  String  headerdata{get;set;}\n    public string urlvalue{get;set;}\n    public string url{get;set;}\n        \n    public pageurlclass(){\n        \n         headerdata= ApexPages.currentPage().getHeaders().get('Host');\n        \n         urlvalue=Apexpages.currentPage().getUrl();\n        \n         url='https:\/\/' + headerdata+ urlvalue;\n    }\n  \n\n}\n\n<\/pre>\n\n\n\n<p><strong>Visualforce Page<\/strong> : Create visualforce page with name Pageurl<\/p>\n\n\n\n<pre class=\"wp-block-preformatted brush:xml\">&lt;apex:page controller=\"pageurlclass\"&gt;\n\n   &lt;!-- \n        \/**\n         * Webkul Software.\n         *\n         * @category  Webkul\n         * @author    Webkul\n         * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https:\/\/webkul.com)\n         * @license   https:\/\/store.webkul.com\/license.html\n         *\/\n         --&gt;\n      \n  1.  {!headerdata}\n\n  2.  {!urlvalue}\n\n  3.  {!url}\n\n&lt;\/apex:page&gt;<\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<p>1. c.ap2.visual.force.com<\/p>\n\n\n\n<p>2. \/apex\/Pageurl<\/p>\n\n\n\n<p>3. https:\/\/c.ap2.visual.force.com\/apex\/Pageurl<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I am going to share the information How To Get Current Page URL from Apex code in Salesforce. So we need to use Apexpages.currentPage() methods.<\/p>\n","protected":false},"author":59,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1889,2383,1887,1888],"tags":[1884,3230,3231,1885],"class_list":["post-51536","post","type-post","status-publish","format-standard","hentry","category-apex","category-blog","category-salesforce","category-visualforce","tag-apex","tag-get-current-page-url","tag-how-to-get-current-page-url-from-apex","tag-salesforce"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Get Current Page URL from Apex code Salesforce<\/title>\n<meta name=\"description\" content=\"In this post, you will learn, How To Get Current Page URL from Apex code in Salesforce. We need to use Apexpages.currentPage() methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Get Current Page URL from Apex code Salesforce\" \/>\n<meta property=\"og:description\" content=\"In this post, you will learn, How To Get Current Page URL from Apex code in Salesforce. We need to use Apexpages.currentPage() methods.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-10T15:55:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-16T12:28:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nansi Kela\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nansi Kela\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/\"},\"author\":{\"name\":\"Nansi Kela\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/550b6aef284dc2b9d85f8532d05a40b8\"},\"headline\":\"How To Get Current Page URL from Apex code\",\"datePublished\":\"2016-06-10T15:55:14+00:00\",\"dateModified\":\"2021-07-16T12:28:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/\"},\"wordCount\":131,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"Apex\",\"Get Current Page URL\",\"How To Get Current Page URL from Apex\",\"Salesforce\"],\"articleSection\":[\"Apex\",\"blog\",\"Salesforce\",\"Visualforce\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/\",\"url\":\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/\",\"name\":\"How To Get Current Page URL from Apex code Salesforce\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2016-06-10T15:55:14+00:00\",\"dateModified\":\"2021-07-16T12:28:29+00:00\",\"description\":\"In this post, you will learn, How To Get Current Page URL from Apex code in Salesforce. We need to use Apexpages.currentPage() methods.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Get Current Page URL from Apex code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/550b6aef284dc2b9d85f8532d05a40b8\",\"name\":\"Nansi Kela\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f330d16c8f951a609b52375b27d65ca770ad3b17c39246e85f563004947de40a?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f330d16c8f951a609b52375b27d65ca770ad3b17c39246e85f563004947de40a?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Nansi Kela\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/nansi\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Get Current Page URL from Apex code Salesforce","description":"In this post, you will learn, How To Get Current Page URL from Apex code in Salesforce. We need to use Apexpages.currentPage() methods.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/","og_locale":"en_US","og_type":"article","og_title":"How To Get Current Page URL from Apex code Salesforce","og_description":"In this post, you will learn, How To Get Current Page URL from Apex code in Salesforce. We need to use Apexpages.currentPage() methods.","og_url":"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-06-10T15:55:14+00:00","article_modified_time":"2021-07-16T12:28:29+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Nansi Kela","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Nansi Kela","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/"},"author":{"name":"Nansi Kela","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/550b6aef284dc2b9d85f8532d05a40b8"},"headline":"How To Get Current Page URL from Apex code","datePublished":"2016-06-10T15:55:14+00:00","dateModified":"2021-07-16T12:28:29+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/"},"wordCount":131,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["Apex","Get Current Page URL","How To Get Current Page URL from Apex","Salesforce"],"articleSection":["Apex","blog","Salesforce","Visualforce"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/","url":"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/","name":"How To Get Current Page URL from Apex code Salesforce","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2016-06-10T15:55:14+00:00","dateModified":"2021-07-16T12:28:29+00:00","description":"In this post, you will learn, How To Get Current Page URL from Apex code in Salesforce. We need to use Apexpages.currentPage() methods.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/how-to-get-current-page-url-from-apex-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Get Current Page URL from Apex code"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/550b6aef284dc2b9d85f8532d05a40b8","name":"Nansi Kela","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f330d16c8f951a609b52375b27d65ca770ad3b17c39246e85f563004947de40a?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f330d16c8f951a609b52375b27d65ca770ad3b17c39246e85f563004947de40a?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Nansi Kela"},"url":"https:\/\/webkul.com\/blog\/author\/nansi\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/51536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/59"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=51536"}],"version-history":[{"count":19,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/51536\/revisions"}],"predecessor-version":[{"id":296557,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/51536\/revisions\/296557"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=51536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=51536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=51536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}