2012-03-01 62 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