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

时间:2015-06-26 17:46:08

标签: c# api salesforce

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

1 个答案:

答案 0 :(得分:1)

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