Search code examples
.netsalesforcecloudtoolkit

Salesforce API not available for this partner or organisation


I am new to salesforce and had created a trial account on the site. I am trying to run a sample for the salesforce .net toolkit given here

Now when I run the following code

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using Salesforce.Common;
using Salesforce.Common.Models;
using Salesforce.Force;
using System.Threading.Tasks;
using System.Dynamic;
namespace ConsoleApplication3
{
    class Program
    {
        #pragma warning disable 618
        private static readonly string SecurityToken =             ConfigurationSettings.AppSettings["SecurityToken"];
        private static readonly string ConsumerKey = ConfigurationSettings.AppSettings["ConsumerKey"];
        private static readonly string ConsumerSecret = ConfigurationSettings.AppSettings["ConsumerSecret"];
        private static readonly string Username = ConfigurationSettings.AppSettings["Username"];
        private static readonly string Password = ConfigurationSettings.AppSettings["Password"]     + SecurityToken;
        private static readonly string IsSandboxUser = ConfigurationSettings.AppSettings["IsSandboxUser"];
        #pragma warning restore 618
        static void Main()
        {
            try
            {
                var task = RunSample();
                task.Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                var innerException = e.InnerException;
                while (innerException != null)
                {
                    Console.WriteLine(innerException.Message);
                    Console.WriteLine(innerException.StackTrace);

                    innerException = innerException.InnerException;
                }
            }
        }

        private static async Task RunSample()
        {
            var auth = new AuthenticationClient();

            // Authenticate with Salesforce
            Console.WriteLine("Authenticating with Salesforce");
            var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)          ?"https://test.salesforce.com/services/oauth2/token":https://login.salesforce.com/services/oauth2/token";

            await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, ".net-    api-client", url);

            Console.WriteLine("Connected to Salesforce");

            var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);
            // retrieve all accounts
            Console.WriteLine("Get Accounts");
            var qry = "SELECT ID, Name FROM Account";
            var accts = new List<Account>();
            var totalSize = 0;

            try
            {
                QueryResult<Account> results = await client.QueryAsync<Account>(qry);
                totalSize = results.totalSize;
                Console.WriteLine("Queried " + totalSize + " records.");

                accts.AddRange(results.records);
                var nextRecordsUrl = results.nextRecordsUrl;

                if (!string.IsNullOrEmpty(nextRecordsUrl))
                {
                    Console.WriteLine("Found nextRecordsUrl.");

                    while (true)
                    {
                        QueryResult<Account> continuationResults = await     client.QueryContinuationAsync<Account>(nextRecordsUrl);
                        totalSize = continuationResults.totalSize;
                        Console.WriteLine("Queried an additional " + totalSize + " records.");

                        accts.AddRange(continuationResults.records);
                        if (string.IsNullOrEmpty(continuationResults.nextRecordsUrl)) break;

                        //pass nextRecordsUrl back to client.QueryAsync to request next set of     records
                        nextRecordsUrl = continuationResults.nextRecordsUrl;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine("Retrieved accounts = " + accts.Count() + ", expected size = " +     totalSize);
        var inp = Console.Read();

        }

        private class Account
        {
            public const String SObjectTypeName = "Account";

            public String Id { get; set; }
            public String Name { get; set; }
        }
    }
}

On running the above code I get the exception message API not enabled for this organisation or partner, on execution of this line QueryResult<Account> continuationResults = await client.QueryContinuationAsync<Account>(nextRecordsUrl);

I have update the app.config to contain the consumer key, secret key, token , username and password. The consumer key and secret key is from a connected app which has the following configuration

connected app

What is wrong?


Solution

  • You are using a trial account, which doesn't include API acceess, you can sign up for a free developer edition account that includes API access.