3

We have a controller for a force.com site visualforce page with logic that depends on the url used to get to the page. For the live site this would be a custom url mapped to the page which the controller controls.

So we have 2 custom urls both of which are mapped to this VF page:
home.ourdomain.com
portal.ourdomain.com

And the controller uses those domains in the controller as follows:

String urlStr = ApexPages.currentPage().getUrl();
if(urlStr.containsIgnoreCase('home')) {
    // some logic then redirect to the home page
} else if(urlStr.containsIgnoreCase('portal')) {
    // other logic then redirect to the portal page
}

The problem is that when testing in a sandbox, the url to reach this page is not the custom url because that is always mapped to the live site. But rather we have to use the standard force.com url for our sandbox e.g. sandboxname-salesforcesitedomain.csxx.force.com/sitename/visualforcepage.

This means that we have to make sure that the controller can handle the urls of the live site and the sandbox orgs, but obviously it would be better to be able to have exactly the same logic work for both the sandbox and the live site. A good solution would be to map custom domains to the sandbox sites e.g. sandboxname.home.oursite.com and sandboxname.portal.oursite.com. But having read this page, I see it says:

Custom Web addresses are not supported for sandbox or Developer Edition organizations.

So am I right in saying that it won't be possible to set up CNAME records to point to our sandbox org? If it is possible, how does one find the correct location to point the CNAME record to?

Many thanks

4

Yes to the best of my knowledge, we cannot have CNAMES for the sandbox org. We ran into a similar issue during our portal deployment. We had to test the CNAME directly in production. We had a week of pre-go live testing in the Production org before rolling it out.

For some of the URL/path issues I found this article to be helpful especially using

{!$Page.pageName}

http://www.sundoginteractive.com/sunblog/posts/a-couple-force.com-sites-url-tips

1

We ran into this brick wall also. Here's the article from Salesforce which says that you cannot use custom domains on Sandbox orgs.

https://help.salesforce.com/apex/HTViewSolution?urlname=Setting-Up-Custom-Domains-for-Salesforce-Sites-and-Setting-up-HTTPS-Support-for-Branded-Custom-Domains&language=en_US

It's a problem for us, because we are serving web font files from our own servers to the Force.com site. We need to have our sandboxes be under the same domain name as our servers, or the font files will be blocked from loading, because it's going across domains.

Just when you thought your project was going to work out as expected... Salesforce strikes again!

0

You could compare to a @TestVisible variable that you reassign in your tests.

public class MyController
{
    @TestVisible String HOME_SUBURL = 'home';
    @TestVisible String PORTAL_SUBURL = 'portal';

    public MyController()
    {
        // or wherever
        String urlStr = ApexPages.currentPage().getUrl();
        if(urlStr.containsIgnoreCase(HOME_SUBURL)) {
            // some logic then redirect to the home page
        } else if(urlStr.containsIgnoreCase(PORTAL_SUBURL)) {
            // other logic then redirect to the portal page
        }
    }
}

Then in your test just set whichever URL substring you are testing to '.com' or whatever partial match you wish. Probably best to be environment agnostic for deployment purposes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.