We've created C# classes for the WSDL file provided by Salesforce.
Most of the classes generated are entity c开发者_StackOverflowlasses, but it seems you don't have any methods to call such as CreateAccount or UpdateAccount.
Is that correct? Do you use a query to do all data manipulation directly?
Instead of having separate create methods for each of the object, Salesforce provides a generic method of create which accepts input of generic object which can be of type account or contact or any custom object.
/// 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);
}
} `
Yes, that is correct. You have no methods in those objects and all operations are to be done using their api (web services).
Here is some sample code in Java and C#
Most of the classes, like Account, Contact etc are really just data structures that go over the wire. The SforceService (if you're using web reference, not sure what the class is called with WCF), is the entry point for doing things with them, you can for example pass a list of Accounts to the create method to have them created on the salesforce side, there's a number of examples in the web services API docs. Query is readonly only, you can't make changes via the query call.
精彩评论