我们为Salesforce提供的WSDL文件创建了C#类。
生成的大多数类都是实体类,但似乎没有任何方法可以调用,如CreateAccount或UpdateAccount。
这是对的吗?您是否使用查询直接进行所有数据操作?
答案 0 :(得分:3)
而不是为每个对象分别创建create方法,Salesforce提供了一个通用的create方法,它接受泛型对象的输入,可以是account或contact类型的输入,也可以是任何自定义对象。
/// 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);
}
} `
答案 1 :(得分:2)
是的,这是正确的。这些对象中没有方法,所有操作都是使用api(Web服务)完成的。
Here是Java和C#中的一些示例代码
答案 2 :(得分:1)
大多数类,如Account,Contact等,实际上只是数据结构。 SforceService(如果您使用Web引用,不确定使用WCF调用哪个类)是使用它们执行操作的入口点,您可以例如将一个Accounts列表传递给create方法以在其上创建它们在salesforce方面,web services API docs中有很多例子。 查询只是只读,您无法通过查询调用进行更改。