2014-10-18 43 views
0

我是新來的salesforce,並在該網站上創建了一個試用帳戶。 我想運行給出hereSalesforce API不適用於此合作伙伴或組織

現在,當我運行下面的代碼

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; } 
     } 
    } 
} 

在運行上面的代碼中,我得到的異常消息API not enabled for this organisation or partner Salesforce的.NET工具包樣本,在此執行line QueryResult<Account> continuationResults = await client.QueryContinuationAsync<Account>(nextRecordsUrl);

我已更新app.config以包含使用者密鑰,密鑰,令牌,用戶名和密碼。 消費者密鑰和祕密密鑰是從具有以下配置

connected app

什麼不對所連接的應用程序?

回答