function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
zen_njzen_nj 

geturl returns partial, can work in sandbox but not in production since it points to sandbox

Hi


I am new to visualforce so am probably doing things by trial and error and looking at examples (and so not getting the whole picture).

 

But I have controller extension for a custom object (call it FSL) and part of what the controller extension is trying to do is to generate a case off the save of this FSL custom object (PageReference save() function) and then have in the Case Description field the value of the full url of this custom object's entry.

 

Specifically, if this custom object entryhas id of xxxyyz and I am in my sandbox instance, then I want to be able to have in Case Description something like 'For more detail on this object, please refer to '+CustomObject_Link;  and the CustomerObject_Link would return say https://tapp0.salesforce.com/xxxyyz.

 

Right now, I  have the following code:

 

public PageReference Save() {

PageReference CustomObject_Link = new PageReference('/' + FSL.id);

.

.

cases.Description='You can see more detail for the FSL entry related to this request by clicking on this link: '+CustomObject_Link;

 

 

And when the case is generated, the Case Description would just contain:

 

 You can see more detail for the FSL entry related to this request by clicking on this link:/xxxyyz.

 

 

I can hardcode the CustomObject_link in sandbox so that it has:

public PageReference Save() {

PageReference CustomObject_Link = 'https://tapp0.salesforce.com'+new PageReference('/' + FSL.id);

 

And this will allow Case Description to contain:

 You can see more detail for the FSL entry related to this request by clicking on this link:https://tapp0.salesforce.com/xxxyyz.

 

Problem is when I bring this to production, we have a different instance (i.e. it would be https://na2.salesforce.com).

 

So how does one extract the instance information (i.e. that it's na2 instead of tapp0) in visualforce so I can do something like:

 

  PageReference CustomObject_Link = 'https://'+CurrentInstance+'.salesforce.com'+new PageReference('/' + FSL.id);

 

Or how do I just issue a PageReference properly so that it would return the full url (https://<salesforce instance url>/xxyyz) and not just /xxxyyz?

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Rajesh ShahRajesh Shah

Hi,

 

You can use a custom object/ custom settings  to store the url details for different instance. Check the following post:

http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=6200

 

All Answers

Rajesh ShahRajesh Shah

Hi,

 

You can use a custom object/ custom settings  to store the url details for different instance. Check the following post:

http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=6200

 

This was selected as the best answer
zen_njzen_nj

Thx Rajesh

 

I couldn't get it to work seamlessly, but at least now I can get it working without changing the code when I port it between sandbox and production (with a little bit hard-coding that I need to maintained).


Essentially, I have a sandbox environment (tapp0 which calls on c.cs0.visual.force.com) and a production environment (na2 which calls on c.na2.visual.force.com),

 

So in my code, I have added the following new stuff:

 

PageReference FSLpage = new PageReference('/' + FSL.id);
string host = ApexPages.CurrentPage().getHeaders().get('Host');

// c.cs0.visual.force.com  refers to tapp0.salesforce.com
// c.na2.visual.force.com   reers to na2.salesforce.com
host = host.replace('visual.force','salesforce');
host = host.replace('c.cs0','tapp0');
host = host.replace('c.na2','na2');
FSL_Link = 'https://'+host+FSLpage.getURL();

 

And then in case description, it would just reference FSL_Link as is and it will return either: https://tapp0.salesforce.com/xxxyz

or

https:/na2.salesforce.com/xxxyz

 

depending on if I am running this in sandbox or production