更新在 SalesForce API 中不起作用 [英] Update not working in SalesForce API

查看:26
本文介绍了更新在 SalesForce API 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 SalesForce API(企业 WSDL)更新记录.

I'm trying to update a record via the SalesForce API (Enterprise WSDL).

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

The code below executes fine, and the saveResult returned says that the operation was successful.

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

Yet, when I look in SalesForce - the record has not been updated. The only thing that I can think of is that I am using the wrong Id - But I have quintuple checked this and checked it again and then re-checked it.

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

Has anybody encountered something like this before? Alternatively, I will be so pleased if someone can point out the stupid mistake that I've probably made somewhere :-)

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));
        }

推荐答案

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

When using .Net to call the Update method on the API, you need to set the *fieldname__cSpecified* field explicitly. E.g.

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

这篇关于更新在 SalesForce API 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆