所以我们有一个数据结构'Case',例如返回案例,退款案例等等。其中一个字段是'CaseComments'字段。该字段是(在C#wsdl生成的代码中)一个QueryResult字段。
我知道要查询CaseComments,我可以使用:
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.
但是如果我尝试在caseComment数据结构上使用create(),它会毫无错误地插入,但是没有恰当地与Case相关联,我似乎无法找到它们。
答案 0 :(得分:1)
对您有用的惊喜,您可能想要检查新案例评论是否实际上正在保存。在APEX中,如果您尝试写入子关系字段(即updateCase.CaseComents.records = (sObject[]) new CaseComment[1];
),则会出现异常,尽管您可以将记录添加到数组中,即使它们不会更新。
例如,这会抛出错误
Case updateCase = new Case();
updateCase.caseComments = new List<CaseComment>(); // throws compile error in APEX
您可以这样做,但不会保存新案例评论。
Case updateCase = [select (select id from CaseComments) from Case where id = '1234'];
updateCase.caseComments.add(new CaseComment(commentBody = 'comment));
binding.update(new sObject[]{ updateCase });
正确的方法是在单独的DML语句中创建它们
CaseComment newComment = new CaseComment();
newComment.parentId = caseToAddToId;
newComment.commentBody = noteToAdd;
binding.update(new sObject[] { newComment });