0

Good afternoon, I'm having a bit of trouble updating a record using JSForce. I would like to update a single field named "BrightPath_Result__c", which is a field of "Deal__c". It seems I can connect fine and start the operation, but I do not have permission to update all of the fields. I'm not trying to update all the fields, just the one specified. I'm sure there's an error in my logic as I'm new to JSForce and coding in general. I searched around but couldn't find anything that addresses this specific issue.

var jsforce = require('jsforce');
var conn = new jsforce.Connection();


conn.login('user', 'password', function(err, res) {
  if (err) { return console.error(err); }
  conn.sobject('Deal__c').retrieve('a5I3o000001dXdC', function(err, record){
    if(err){console.log(err)}
    console.log(record.BrightPath_Result__c)
    record.BrightPath_Result__c = "Not Feasible"
    conn.sobject("Deal__c").update(record, function(err, res){
      if(err){console.log(err)}
      if(res){console.log(record.BrightPath_Result__c)}
    })
  })

})

Output:

Feasible

INVALID_FIELD_FOR_INSERT_UPDATE: Unable to create/update fields: Payment_Amount_Year_3__c, Property_Classification__c, SF2_Days_Contract_Approved_to_Feasible__c. Please check the security settings of this field and verify that it is read/write for your profile or permission set. (Etc... there's about 170+ fields that I do not have permission to update.)

I am not the owner of the Salesforce account, I simply work for the company and I'm working on a desktop app for our employees to use. They won't have developer permissions, so the solution needs to take that in mind. Thank you for your time and expertise!

0

You're unnecessarily retrieving the entire record, which means you're trying to overwrite everything, even though you only need to update one field. This is both wasteful, and, as you've observed, problematic. You can set just the fields you need:

  conn.sobject('Deal__c').update({
    Id: 'a5I3o000001dXdC',
    BrightPath_Result__c: "Not Feasible"
  }, function(err, res) {
    if(err){console.log(err)}
    if(res){console.log(record.BrightPath_Result__c)}
  })
  • Awesome! It worked great. Out of curiosity, would I be able to update multiple fields by just Id: ___ , field1 : value, field2 :value, callback or would I need to put the edited entries into an array? – PaulyP Oct 1 '20 at 18:13
  • @PaulyP Yes, you can add more fields to this object, as many as you need. The field-values go inside the {}, the callback goes after. – sfdcfox Oct 1 '20 at 18:25
  • Thank you so much for your insight. Last question, I promise! Say I wanted to upload a file to the custom object or create a new custom object with a file from my local machine. Would I be able to do something like Panel_Image__c: ${filevariable}? – PaulyP Oct 1 '20 at 19:10
  • @PaulyP You'd deserialize it to a native object first, such as: sobject('Panel_Image__c').insert(JSON.parse(filevariable)). I don't know if JSForce can read the file directly, you need to use the fs module in node to read the file into memory first. – sfdcfox Oct 1 '20 at 19:19
  • @PaulyP the ID is returned in res as part of the response. – sfdcfox Oct 1 '20 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.