Salesforce API 帐户创建

发布于 2024-11-09 16:00:25 字数 148 浏览 0 评论 0原文

我们已经为 Salesforce 提供的 WSDL 文件创建了 C# 类。

生成的大多数类都是实体类,但似乎您没有任何方法可以调用,例如 CreateAccount 或 UpdateAccount。

这是正确的吗?您是否使用查询直接执行所有数据操作?

We've created C# classes for the WSDL file provided by Salesforce.

Most of the classes generated are entity classes, 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心头的小情儿 2024-11-16 16:00:25

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

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);
    }
}  `
剧终人散尽 2024-11-16 16:00:25

是的,这是正确的。这些对象中没有方法,所有操作都将使用它们的 api(Web 服务)来完成。

这里是一些 Java 示例代码和 C#

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#

不回头走下去 2024-11-16 16:00:25

大多数类,如帐户、联系人等实际上只是通过网络传输的数据结构。 SforceService(如果您使用的是 Web 引用,不确定使用 WCF 调用该类)是使用它们执行操作的入口点,例如,您可以将帐户列表传递给 create 方法以在其上创建它们在 salesforce 方面,Web 服务 API 文档。
查询是只读的,您无法通过查询调用进行更改。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文