通过Salesforce API C#添加新的案例注释

本文关键字:案例 注释 添加 Salesforce API 通过 | 更新日期: 2023-09-27 17:59:53

我正在使用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);
                }
           }
    }
}

通过Salesforce API C#添加新的案例注释

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