【问题标题】:restforce gem save only changed attriubtes?restforce gem 只保存更改的属性?
【发布时间】:2017-10-31 13:48:58
【问题描述】:

我正在使用restforce 与Ruby on Rails 中的salesforce 交互。 我有这段代码:

client = Restforce.new
acc = client.find("Account", account_ID)
acc.firstName = "test"
acc.save
# if I use update I get the same error
acc.update

但我收到以下错误

[
    {
        "message":"Unable to create/update fields: jigsaw_clean__Sync_Status_Indicator__c, LastModifiedDate, PhotoUrl, IsDeleted, jigsaw_clean__Jigsaw_Managed_Backend__c, jigsaw_clean__Sync_Status_Summary__c, AccPwr1__c, BillingAddress, jigsaw_clean__Duplicate__c, LastActivityDate, jigsaw_clean__Automatic_Updates__c, JigsawCompanyId, CreatedById, MasterRecordId, LastViewedDate, CreatedDate, LastReferencedDate, jigsaw_clean__Additional_Information__c, jigsaw_clean__Jigsaw_Last_Sync_Locked__c, Cross_Sell_Score__c, jigsaw_clean__Jigsaw_Managed__c, ShippingAddress, LastModifiedById, IANA_Number_field__c. Please check the security settings of this field and verify that it is read/write for your profile or permission set.",
        "errorCode":"INVALID_FIELD_FOR_INSERT_UPDATE",
        "fields":[
            "jigsaw_clean__Sync_Status_Indicator__c",
            "jigsaw_clean__Jigsaw_Managed_Backend__c",
            "jigsaw_clean__Sync_Status_Summary__c",
            "AccPwr1__c",
            "BillingAddress",
            "jigsaw_clean__Duplicate__c",
            "LastActivityDate",
            "jigsaw_clean__Automatic_Updates__c",
            "CreatedById",
            "MasterRecordId",
            "jigsaw_clean__Additional_Information__c",
            "jigsaw_clean__Jigsaw_Last_Sync_Locked__c",
            "Cross_Sell_Score__c",
            "jigsaw_clean__Jigsaw_Managed__c",
            ]
    }
] 

和其他领域。

我知道,我可以这样做:

client = Restforce.new
acc = client.find("Account", account_ID)
acc1 = {Id: acc.Id}
acc1["firstName"] = "test"
client.update("Account", acc1)

如何以更有效的方式做到这一点?

【问题讨论】:

    标签: ruby-on-rails salesforce restforce


    【解决方案1】:

    请检查此字段的安全设置,并验证您的个人资料或权限集是否可以读取/写入。

    您确定您有权进行更新吗?

    【讨论】:

    • 我有权进行更新。但我从不更新这些字段。我不想更新它们。我只想更新更改的字段。我知道我可以使用查询来选择想要的字段,但我不想这样做。
    【解决方案2】:

    我能找到的唯一方法是不使用 find,而是使用查询我们想要更新的字段。

    client = Restforce.new
    acc1 = client.query("SELECT ID, firstName, LastName FROM Account where ID = '#{account_ID}'").first
    acc1["firstName"] = "test"
    acc1.save
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-15
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多