C# 通过Salesforce API C添加新案例注释
我正在使用Salesforce企业WSDL在定制的C web应用程序上管理Salesforce案例。我已经成功地更新了案例所有者,但是我不知道如何在案例中添加注释。下面是我更新案例所有者的代码。如何添加新的案例注释C# 通过Salesforce API C添加新案例注释,c#,api,salesforce,C#,Api,Salesforce,我正在使用Salesforce企业WSDL在定制的C web应用程序上管理Salesforce案例。我已经成功地更新了案例所有者,但是我不知道如何在案例中添加注释。下面是我更新案例所有者的代码。如何添加新的案例注释 public void UpdateCase(SalesforceLogin currentLogin, String caseId, String userId, String newComment) { sfdcBinding.Url = curr
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);
}
}
}
}
您需要使用单独的对象,将ParentId设置为目标案例Id。我尝试使用添加到原始注释中的代码。该注释从未实际添加,也没有抛出错误。结果表明,它出错是因为我设置了用户idCreatedById=userId。当我删除那行代码时,它起作用了。谢谢@您是否检查了create方法返回的SaveResult?这里面可能有错误,太好了。系统将为您设置CreatedById和LastModifiedId字段。