【问题标题】:Update not working in SalesForce API更新在 SalesForce API 中不起作用
【发布时间】:2012-03-01 14:46:51
【问题描述】:

我正在尝试通过 SalesForce API (Enterprise WSDL) 更新记录。

下面的代码执行正常,返回的saveResult表示操作成功。

然而,当我查看 SalesForce 时 - 记录尚未更新。我唯一能想到的是我使用了错误的 ID - 但我已经检查了五次并再次检查了它,然后重新检查了它。

有没有人遇到过这样的事情?或者,如果有人能指出我可能在某处犯过的愚蠢错误,我会很高兴:-)

sforce.Participant__c updateParticipant = new sforce.Participant__c();

        updateParticipant.Id = participant.Id.Length == 15? participant.Id : participant.Id.Substring(0, 15);

        if (updateType == "pre")
        {
            updateParticipant.Manual_Download_Date__c = DateTime.Now;
            updateParticipant.Manual_Download__c = true;
        }
        else if (updateType == "post")
        {
            updateParticipant.Post_Class_Manual_Download__c = true;
            updateParticipant.Post_Class_Manual_Downloaded_Date__c = DateTime.Now;
        }

        sforce.SaveResult[] result = SFLib.sfdc.update(new sforce.sObject[] { updateParticipant });
        if (result == null || result.Length <= 0)
            return false;
        else
        {
            if (result[0].success == true)
                return true;
            else
                throw new Exception("Update participant failed", new Exception(result[0].errors[0].message));
        }

【问题讨论】:

  • 你应该在下面给出答案并接受你自己的答案,以避免留下这个问题。

标签: c# api salesforce


【解决方案1】:

使用 .Net 调用 API 上的 Update 方法时,需要显式设置 *fieldname__cSpecified* 字段。例如

updateParticipant.aDateField_StartDate__c = DateTime.Now;
updateParticipant.aDateField_StartDate__cSpecified = true;

【讨论】:

  • 虽然这仅适用于某些类型,布尔值/数字/日期,但不适用于字符串。
  • 如果可以的话,我会再次投票,我一直在拔头发
  • 我们花了几个小时试图追踪为什么我们的肥皂客户端无法将 CaseComment.isPublished 设置为 true。谢谢@RobD。此文档位于 SFDC Soap API 开发人员指南 salesforce.com/us/developer/docs/api/… 中“实施注意事项”页面的底部
  • 如果我没有看到这篇文章,我至少要花 10 个小时。非常感谢。
  • @RobD,你刚刚击败了“Premiere”销售团队技术支持。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多