Custom Domain in Salesforce Mobile SDK Solution

When running up an app built with the Salesforce Mobile SDK there is an option to login to a custom domain. This is useful when testing against a sandbox or developer environment. The option, when running on an Android device, is accessible via the Change Server menu item which is available via the hardware menu button.

Screenshot showing menu for setting custom domain in pre 3.0 SDK

The issue comes though if your device doesn’t have a hardware button… what then?

The Solution

If an acceptable option for you is to have this custom domain hard-coded (so that it cant be changed) then you can modify some code to use your defined custom domain as the default. It is as easy as replacing a single line in one file… so let’s have a look. In the below I have commented out one line and replaced it, and in my example I’m setting the default domain to (as in my case I’m testing against a sandbox environment).

This means next time you run-up you can enter your custom domain login credentials without needing to switch server details.

As I have said, this is just a work-around, and is in fact fixed in the Mobile SDK v3.0. But, if you’re stuck using an older SDK then this may prove useful.

In the v3.0 SDK the login screen now looks like this, with a handy menu in the top bar.

Screenshot showing login screen with menu for setting custom domain/server

Happy coding.