Recently I shifted my Android code (using this as base) to support app dynamics sandbox account. I am able to login, fetch data from that account through https://test.salesforce.com.

There is a connected app created in sandbox account and I am using its consumer key and call back url in my Android app.

While executing any SOQL query, I need to make a connection and I am using ConnectorConfig for that.

EnterpriseConnection connection = Connector.newConnection(connectorConfig);
        // query for the 5 newest contacts
        QueryResult queryResults = null;
        if(accountId == null) {
            queryResults = connection.query("SELECT Id, FirstName, LastName, Account.Name " +
                    "FROM Contact WHERE AccountId != NULL ORDER BY CreatedDate DESC LIMIT 5");
        } else {
            queryResults = connection.query("SELECT Id, FirstName, LastName, Account.Name " +
                    "FROM Contact WHERE Account.Id="+"'"+accountId+"'");

To create a ConnectorConfig, I hard coded username and password_security_token.

    connectorConfig = new ConnectorConfig();
    connectorConfig.setPassword(PASSWORD + SECURITY_TOKEN);

Now, my question is, now its fetching data from my account as I hard coded login credentials but what if I want to login as other user? as login credentials will be different for them, will it be able to act same?

Is it right way to do it or is there any proper way?

Can anybody please help me?


  • If your network ip address is added to salesforce account then no need append security token, you can login using just username and password. Create login view/page which take username and password as input. Jan 29, 2014 at 7:02

2 Answers 2


The DreamforcengerHunt code that you are refering to was written 2 years ago - before the force.com Mobile SDK existed - as a result, it does not provide out of the box oAuth, REST API wrappers for firing SOQLs and several other features that the SDK provides.

Just so you know, the app you referred to was re-written as a hybrid Mobile SDK app one year later for Dreamforce 2012. The source code for that app can be found here and there's a comprehensive series of blog posts explaining the architecture and code that can be found here.

Unless there's a strong reason to stick to that obsolete approach, I would recommend you use the Mobile SDK native Android template as a starting point for your application. You would then NOT be using username, password in your code. Instead, you will create a connected app and use the CLIENT_ID and CLIENT_SECRET as part of your native app code template.

If you face any issues in using Force.com Android Mobile SDK native template, please feel free to post another thread.

  • I got ur point. This new approach works for normal salesforce accounts but how can I connect to my sandbox account with this? In that old code, there is a way to change login url to test.salesforce.com (for normal accounts v use login.salesforce.com) which I dont see in new approach
    – Braj
    Jan 30, 2014 at 5:56
  • Thanks for d suggestion. I got to know how to switch between servers (sandbox & production) from success.salesforce.com/answers?id=90630000000h6W2AAI. I will start using d new approach.
    – Braj
    Jan 30, 2014 at 6:38

Why are you using the SOAP API for this? The connected app works with the REST API concept. REST is better for mobile development and it does not require you to store or provide username/password to the app. The authentication responsibility is handed over to Salesforce and your app just needs to coordinate the sequence of steps.

Start here for REST based mobile development with Salesforce http://wiki.developerforce.com/page/Mobile_SDK

  • Tried that way of creating app but could not succeed. Using following app as base github.com/tomgersic/DreamforcengerHunt
    – Braj
    Jan 29, 2014 at 8:58
  • What exactly was the issue with the official Salesforce guide? That link seems to be of code more than 2 years old. Better you look for something newer.
    – AslamK
    Jan 29, 2014 at 10:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .