I am trying to use Salesforce Mobile SDK for native Android. Requirement:
- Allow any user with Salesforce account to login
- Fetch his/her contacts list
- 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:
- Cloned it
- Installed NPM and installed the required submodules
- Created a new Android application using native forcedroid
- 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
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"
}
EDIT 1 : 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();
}
});
}
});
}
EDIT 2 : Some more findings:
I think it has to do with my account/connected app settings. Because when I signedup using https://developer.salesforce.com/signup and used the
username
it works fine. Here again if I used theusername
s using the sameBTW I am currently using a trial version of salesforce.
The REST API is not enabled for this Organization (Salesforce API using databasedotcom gem) in Rails Ask Question Asked8 years, 4 months ago Active6 years, 11 months ago
Sep 3 '13 at 6:53 API Enabled permission will be on the Users Permission Section in the Profile. API Enabled option will be there only for Users of Profile System Administrator or Cloned profiel of System Administrator. na4.salesforce.com/help/doc/en/admin_userperms.htm
Here's how to fix that. First, check on the organization settings. Enterprise, Unlimited and Developer editions has the API enabled by default. Professional Customers can purchase this feature.
You should fine using a developer org .Sign up with a developer org and you can access REST and SOAP API's
regular trial accounts are for Professional Edition, which doesn't include API access, which is the error you're getting. You need to use an account with API access such as a free developer edition account, or an enterprise edition account.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With