2012-03-01 43 views
8

我试图通过SalesForce API(Enterprise WSDL)更新记录。更新无法在SalesForce API中工作

下面的代码执行得很好,并且返回的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)); 
     } 
+0

你应该给出下面的答案,并接受你自己的答案,以避免这个问题开放。 – mmix 2012-03-01 17:12:01

回答

18

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

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

尽管这只适用于某些类型的布尔值/数字/日期,但它不适用于字符串。 – superfell 2012-03-02 02:15:39

+0

我会再次投票,如果我可以,我一直拉我的头发 – Miles 2013-09-05 18:42:34

+2

我们花了几个小时试图追踪为什么我们的肥皂客户端无法将CaseComment.isPublished设置为true。感谢@RobD。该文档位于“SFDC Soap API开发人员指南”的“实施注意事项”页面底部http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content/implementation_considerations。 htm?SearchType = Stem – cropredy 2013-11-25 22:05:10