2011-05-25 180 views
0

我們爲Salesforce提供的WSDL文件創建了C#類。創建salesforce API帳戶

大部分生成的類都是實體類,但似乎您沒有任何方法可以調用,如CreateAccount或UpdateAccount。

這是正確的嗎?你是否使用查詢直接進行所有數據操作?

回答

3

Salesforce不是爲每個對象分別創建方法,而是提供了一種通用的創建方法,該方法接受通用對象的輸入,該通用對象可以是帳戶或聯繫人或任何自定義對象的類型。

/// Demonstrates how to create one or more Account records via the API 

public void CreateAccountSample() 
{ 
    Account account1 = new Account(); 
    Account account2 = new Account(); 

    // Set some fields on the account1 object. Name field is not set 

    // so this record should fail as it is a required field. 

    account1.BillingCity = "Wichita"; 
    account1.BillingCountry = "US"; 
    account1.BillingState = "KA"; 
    account1.BillingStreet = "4322 Haystack Boulevard"; 
    account1.BillingPostalCode = "87901"; 

    // Set some fields on the account2 object 

    account2.Name = "Golden Straw"; 
    account2.BillingCity = "Oakland"; 
    account2.BillingCountry = "US"; 
    account2.BillingState = "CA"; 
    account2.BillingStreet = "666 Raiders Boulevard"; 
    account2.BillingPostalCode = "97502"; 

    // Create an array of SObjects to hold the accounts 

    sObject[] accounts = new sObject[2]; 
    // Add the accounts to the SObject array 

    accounts[0] = account1; 
    accounts[1] = account2; 

    // Invoke the create() call 

    try 
    { 
     SaveResult[] saveResults = binding.create(accounts); 

     // Handle the results 

     for (int i = 0; i < saveResults.Length; i++) 
     { 
      // Determine whether create() succeeded or had errors 

      if (saveResults[i].success) 
      { 
       // No errors, so retrieve the Id created for this record 

       Console.WriteLine("An Account was created with Id: {0}", 
        saveResults[i].id); 
      } 
      else 
      { 
       Console.WriteLine("Item {0} had an error updating", i); 

       // Handle the errors 

       foreach (Error error in saveResults[i].errors) 
       { 
        Console.WriteLine("Error code is: {0}", 
         error.statusCode.ToString()); 
        Console.WriteLine("Error message: {0}", error.message); 
       } 
      } 
     } 
    } 
    catch (SoapException e) 
    { 
     Console.WriteLine(e.Code); 
     Console.WriteLine(e.Message); 
    } 
} ` 
2

是的,這是正確的。這些對象中沒有方法,所有操作都是使用它們的API(Web服務)完成的。

Here是Java的一些示例代碼和C#

+0

所以我會說實體類是作爲存根存在的,但是你必須編寫一個可以編譯這些查詢的bll層,例如,更新查詢,然後使用實體存根將它的值連接到查詢? – Jacques 2011-05-25 16:29:03

+0

綁定.describeSObject方法呢? – Jacques 2011-05-25 16:30:55

+1

@Jacques:是的,我們製作了一個圖層,用於編譯這些查詢以加載和保存一個對象,以及一個集合類,它編譯用於使用where子句加載對象的查詢。 – 2011-05-25 18:03:49

1

大多數類,如客戶,聯繫人等是真的走了過來線只是數據結構。 SforceService(如果您使用的是Web引用,不知道該類是通過WCF調用的)是用於處理它們的入口點,例如可以將一系列帳戶傳遞給create方法以使其創建銷售人員方面,web services API docs中有許多例子。 查詢只能讀取,不能通過查詢調用進行更改。