Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

I am trying to use the Salesforce Mobile SDK for native Android. Requirement:

  1. Allow any user with Salesforce account to login
  2. Fetch his/her contacts list
  3. Fetch particular contact details

Please let me know if those are not part of the Mobile SDK.

I followed https://github.com/forcedotcom/SalesforceMobileSDK-Android:

  1. Cloned it
  2. Installed NPM and installed the required submodules
  3. Created a new Android application using native forcedroid
  4. Changed the bootconfig.xml values with the values of my connected app.

It logs in fine but when I try to fetch the contacts, it says:

The Rest API is not enabled for this Organization

enter image description here

The login response seems to be fine. Client object json credentials:

{

  "clientId": "*******",

  "loginUrl": "https://login.salesforce.com",

  "identityUrl": "https://login.salesforce.com/id/99VVHJHGF5688/00548000003yOKeAAM",

  "instanceUrl": "https://ap2.salesforce.com",

  "userId": "**********",

  "orgId": "*********",

  "communityUrl": null,

  "refreshToken": "*************",

  "accessToken": "************",

  "communityId": null,

  "userAgent": "SalesforceMobileSDK/4.3.0 android mobile/7.0 (Nexus 6P) SFTest/1.0 Native uid_32aea9bdde1b8b7e"

}

Code to get Contacts list:

public void onFetchContactsClick(View v) throws UnsupportedEncodingException {

    sendRequest("SELECT Name FROM Contact");

}

private void sendRequest(String soql) throws UnsupportedEncodingException {

    RestRequest restRequest = RestRequest.getRequestForQuery(ApiVersionStrings.getVersionNumber(this), soql);

    client.sendAsync(restRequest, new AsyncRequestCallback() {

        @Override

        public void onSuccess(RestRequest request, final RestResponse result) {

            result.consumeQuietly(); // consume before going back to main thread

            runOnUiThread(new Runnable() {

                @Override

                public void run() {

                    try {

                        listAdapter.clear();

                        JSONArray records = result.asJSONObject().getJSONArray("records");

                        for (int i = 0; i < records.length(); i++) {

                            listAdapter.add(records.getJSONObject(i).getString("Name"));

                        }

                    } catch (Exception e) {

                        onError(e);

                    }

                }

            });

        }

        @Override

        public void onError(final Exception exception) {

            runOnUiThread(new Runnable() {

                @Override

                public void run() {

                    Toast.makeText(MainActivity.this,

                            MainActivity.this.getString(SalesforceSDKManager.getInstance().getSalesforceR().stringGenericError(), exception.toString()),

                            Toast.LENGTH_LONG).show();

                }

            });

        }

    });

}

BTW I am currently using a trial version of salesforce.

1 Answer

0 votes
by (32.1k points)
edited by
Well, since you're using a trial account, let's me tell you that regular trial accounts are for Professional Edition. They don't include API access, which is the error you're getting. You just need to use an account with API access such as a free developer edition account, or an enterprise edition account.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...