Question:

Site.com visualforce page refresh

Skylar: 2 weeks ago

I want to refresh a site.com visualforce page on submission of a form, adding an additional query string parameter, but when I try and get the current page url it returns the /apex/controllerName route rather than the name of the page on the public facing site.

private String hostName = ApexPages.currentPage().getHeaders().get('Host');

private String url = ApexPages.currentPage().getURL();

private String thisPageUrl = 'https://' + hostName + '/' + url + '&submitted=true';

return new PageReference(thisPageUrl);

I want this to return in format: http:// myform-org.cs99.force.com/testform?currentId=R4Rl00000009YuV&submitted=true

but currently I get: https:// myform-org.cs99.force.com//apex/mytestFormController?currentId=R4Rl00000009YuV&submitted=true

Answer:
Natalia: 2 weeks ago

You should be using Site.getBaseUrl() instead of the Host parameter. See the Site (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_sites.htm) class for more information.