C# Salesforce是否插入/更新查询结果字段?

C# Salesforce是否插入/更新查询结果字段?,c#,soap,wsdl,salesforce,C#,Soap,Wsdl,Salesforce,因此,我们有一个数据结构“案例”,如退货案例、退款案例等。其中一个字段是“案例评论”字段。该字段是(在C#wsdl生成的代码中)QueryResult字段 我知道要查询案例评论,我可以使用: SELECT (SELECT ParentId, CommentBody FROM Case.CaseComments) FROM Case 获取所有案例注释的ParentId和CommentBody字段。然而,我没有得到插入,也没有找到任何关于如何做的合理文档 我更喜欢使用强类型查询,例如: C

因此,我们有一个数据结构“案例”,如退货案例、退款案例等。其中一个字段是“案例评论”字段。该字段是(在C#wsdl生成的代码中)QueryResult字段

我知道要查询案例评论,我可以使用:

SELECT (SELECT ParentId, CommentBody FROM Case.CaseComments) FROM Case
获取所有案例注释的ParentId和CommentBody字段。然而,我没有得到插入,也没有找到任何关于如何做的合理文档

我更喜欢使用强类型查询,例如:

    Case updateCase = new Case();
    updateCase.Id = caseToAddToID;
    updateCase.CaseComments = new QueryResult();
    updateCase.CaseComments.records = (sObject[])new CaseComment[1];
    updateCase.CaseComments.records[0] = new CaseComment();
    ((CaseComment)updateCase.CaseComments.records[0]).ParentId = caseToAddToID;
    ((CaseComment)updateCase.CaseComments.records[0]).CommentBody = noteToAdd;

    binding.update(new sObject[]{updateCase});
但当我做这样的事情时,我会出错:

    Error: getting record type info.
    INVALID_FIELD: No such column 'CaseComments' on entity 'Case'. 
    If you are attempting to use a custom field, be sure to append 
    the '__c' after the custom field name. Please reference your WSDL
    or the describe call for the appropriate names.

但是,如果我尝试仅在CaseComent数据结构上使用create(),它会插入而不会出错,但不会与案例适当关联,而且我似乎找不到它们。

您可能希望检查新案例注释是否确实在保存。在APEX中,如果您尝试写入子关系字段(即,
updateCase.CaseComents.records=(sObject[])new CaseComent[1];
),则会出现异常,尽管您可以将记录添加到数组中,即使它们不会被更新

例如,这会抛出一个错误

 Case updateCase = new Case();
 updateCase.caseComments = new List<CaseComment>(); // throws compile error in APEX
正确的方法是在单独的DML语句中创建它们

 CaseComment newComment = new CaseComment();
 newComment.parentId = caseToAddToId;
 newComment.commentBody = noteToAdd;
 binding.update(new sObject[] { newComment });

好吧,我错了。另外,我提供了一个空ID字段。我让它工作了。请看“”。
 CaseComment newComment = new CaseComment();
 newComment.parentId = caseToAddToId;
 newComment.commentBody = noteToAdd;
 binding.update(new sObject[] { newComment });