restforce gem save only changed attriubtes?

149 Views Asked by At

I'm using restforce to interat with salesforce in Ruby on Rails. I have this snippet of code:

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

But I get the following error

[
    {
        "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",
            ]
    }
] 

and other fields.

I know, I can do something like:

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

How do I do this in a more efficient way?

2

There are 2 best solutions below

0
Gamal Tawaf On BEST ANSWER

The only way I can find is the instead of using find we use query with fields that we want to update.

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

Please check the security settings of this field and verify that it is read/write for your profile or permission set.

Are you sure that you have permission to make updates?