You need to sign in to do that
Don't have an account?
Nakata
How can i get the URL ?
Good day All,
May i know how can i get the salesforce site URL ? say if we are in sandbox , it show : https://cs2.salesforce.com
if production , it show me https://na7.salesforce.com ?
I'm using unlimited version.
Thank you !
Try this
Ignacio.
All Answers
Try this
Ignacio.
Cool ....Thank you imuino2!
Sir, can we use Site object to get that ?
Just use Site.getCurrentSiteUrl() method to do that on a site.
Ignacio.
site methods only return value if you are in site context.
if you use them and call them when you are logged in to salesforce (not accessing via your public site) you won't get a value (because system wouldn't know what the current site is).
Hi Bulent,
What if we really want to know whether current salesforce is using what hostname? i believe Apex.currentPage will get null if the controller is not referring a page, what method should we call in this case?
Thank you !
Bulent,
Can you clarify what "site context" means in this case? If we're calling the Site class via Apex code on our Production or Sandbox sites-- isn't that considered within the site context?
If not, I would really appreciate if you could explain when it works/does not work. Trying to prepare for the subdomain change in two weeks and Apex classes are the last place we've hardcoded it in. URLFORs and relative paths don't work in Apex :)
site context means you page is called via the site url (sandbox or production).
if you call the same page when you are logged in to salesforce all the site methods would return null since your page is not called from your site
Hi Bulent,
from your opinion, what is the best way to get Site URL ? i need to differential whether we are in production or development environment from coding wise.
Thank you !
Site.getCurrentSiteUrl() is the way. i you are not testing it via sites then it'll return null.
Thanks Bulent,
If we have a web service class, means it is not under sites so we will get null in this case ? how can we handle if that's happened ?
Hi Bulent,
I guess the null situation is where I'm stuck. I'm running 100% Apex code via a trigger & class, yet the function you mentioned is returning null when I test on our Sandbox. Given that I'm working 100% with Apex code, how can I grab the correct domain for our Force.com URL?
Thanks for any assistance you can provide. Only a few more days until D-Day and need to be able to use the correct URLs!
the correct url would change based on which site is requesting the page. Each site url can be masked with a custom url).
if the call is not made in site context there is no site url to return.
Are there any workarounds-- anything?
Like I said, right now we've manually coded in our server instance (in 2-3 places), something like: https://na3.salesforce.com/ + RelevantId. This isn't always used (usually we can use relative links or PageReference URLs) but in some cases it is unavoidable.
I can manually update this code when our rollover date happens, but what I'd like to do is replace these hard links with something that don't break if our salesforce server changes.
Any ideas?
I want to get the url(apex/PageName?Parameters) of my visual force page saved in a variable.
As my requirment is such that i need to append a new parameter on the exsisting set of parameters in the current URL.
Any help??
I am using developers edition