通过 Salesforce API C# 添加新个案评论

Adding a new case comment via Salesforce API C#

我正在使用 Salesforce Enterprise WSDL 在自定义构建的 C# Web 应用程序上管理 Salesforce 案例。我已经成功地能够更新案例所有者,但是我不知道如何向案例添加评论。我更新案例所有者的代码如下。如何添加新的案例评论?

    public void UpdateCase(SalesforceLogin currentLogin, String caseId, String userId, String newComment)
    {
        sfdcBinding.Url = currentLogin.ServerUrl;
        sfdcBinding.SessionHeaderValue = new SessionHeader();
        sfdcBinding.SessionHeaderValue.sessionId = currentLogin.SessionId;

        String query = "SELECT ID FROM Case WHERE CaseNumber = '" + caseId + "'";
        QueryResult results = sfdcBinding.query(query);

        if (results.records != null && !userId.IsNullOrEmpty())
        {
            SFDC.Case sfCase = results.records.Cast<SFDC.Case>().First();

            if (!sfCase.Id.IsNullOrEmpty())
            {
                sfCase.OwnerId = userId;

                SFDC.sObject[] toUpdate = new SFDC.sObject[1];

                toUpdate[0] = sfCase;
                sfdcBinding.update(toUpdate);

            }
        }
    }

更新:我用来添加评论的代码

public void AddCaseComment(SalesforceLogin currentLogin, String caseId, String userId)
{
        sfdcBinding.Url = currentLogin.ServerUrl;
        sfdcBinding.SessionHeaderValue = new SessionHeader();
        sfdcBinding.SessionHeaderValue.sessionId = currentLogin.SessionId;

        try
        {
            String query = "SELECT ID FROM Case WHERE CaseNumber = '" + caseId + "'";
            QueryResult results = sfdcBinding.query(query);

            if (results.records != null && !userId.IsNullOrEmpty())
            {
                SFDC.Case sfCase = results.records.Cast<SFDC.Case>().First();
                if (!sfCase.Id.IsNullOrEmpty())
                {
                    CaseComment caseComment = new CaseComment()
                    {
                        CommentBody = "test",
                        ParentId = sfCase.Id,
                        CreatedById = userId,
                        IsPublished = true,
                        LastModifiedById = userId
                    };

                    SFDC.sObject[] toCreate = new SFDC.sObject[1];

                    toCreate[0] = caseComment;
                    sfdcBinding.create(toCreate);
                }
           }
    }
}

您将需要使用单独的 CaseComment 对象,并将 ParentId 设置为目标案例 ID。