0

I am trying to update a custom field on the Product2 object, namely S3_Image__c - it is a URL field, linking to an image on AWS S3.

Now, I've basically lifted the code from the examples given on the nforce github, and I believe I have the syntax right.

When I run it, the error I am getting is:

Error: Provided external ID field does not exist or is not accessible: undefined

I have tried setting an external ID and I've tried entering dummy data in S3_Image__c, in case it shouldn't be blank. I am basically out of ideas. Any help would be appreciated!

I've included a lot of code but I don't want to miss a key detail. Sorry if it's too much.

function uploadS3Path(filetype, s3url){
    var outcome;
    return new Promise ( result => {
        var queryFileUpdate = 'SELECT S3_Image__c FROM Product2 WHERE Id = \'01t2w000006aKY5AAM\'';// + Id__c;                
        querySFDC(queryFileUpdate).then( result => {
        if(result.length > 0) {
      
            var acc = result[0];
            if(filetype == 'PDF'){
              acc.set('S3_PDF__c', s3url);
            }
            else{
                acc.set('S3_Image__c', s3url);
            }

            org.update({ sobject: acc }).then( result => {
                console.log(result);
                return result;
            }).catch(error => {
                console.error(error);
            });                
          }                  
    });
    });            
}

function querySFDC(query) {
    return new Promise( result => {
        var queryresult;
        console.log("Query Running: " + query);
        org.query({ query: query }).then( results => {
            if (results.records.length > 0) {
                queryresult = results.records;
            } else {
                console.log("Returned No records");
            }
        result(queryresult);
    });            
    });
}
  • You nforce code doesn't explicitly mention S3_Image__c as an external ID field, but the error message indicates it as external ID field. This tells me that the code while trying to query the SObject was able to identify the field as external ID field. So, I would interpret this message as Provided external ID field is not accessible. You are probably using an user account to authenticate to the org using org.authenticate nforce function. Does this user have access to the external ID field? – arut Aug 26 at 6:59
  • @arut thanks for looking at it. It's in a Dev org, using a System Administrator user. Your comments made me think maybe a URL field is External ID field by default, as you can't select it. So, I created a new Text field, made sure External ID was not checked and tried the code with that field - exact same result. I am beginning to think the issue is in the underlying nforce code. – Scott Harrison Aug 26 at 10:37
  • I created a simple node JS application hosted locally and used to nforce to query an URL field created in Account object. Didn't get any error. – arut Aug 26 at 15:09
  • I can see that you are also using the field S3_PDF__c but not querying for it. Could that be causing the problem? May be provide some more details like where exactly does your code run into this error. – arut Aug 26 at 15:11
  • The S3_PDF__c is inside an If that isn't reached, I am testing with a JPG and a PNG. The error occurs at the org.update(), it is a response to trying to update the record. – Scott Harrison Aug 26 at 21:35
0

Turns out I needed to query the "Id," so it was contained in the sObject. Little bit obvious looking back, but it had me puzzled for a day or so.

For anyone interested in the working code:

function uploadS3Path(filetype, s3url){
            var outcome;
            return new Promise ( result => {
                var queryFileUpdate = 'SELECT Id, S3_Image__c, S3_PDF__c FROM Product2 WHERE Id = \'01t2w000006aKY5AAM\'';// + Id__c;                
                querySFDC(queryFileUpdate).then( result => {
                if(result.length > 0) {
              
                    var acc = result[0];
                    //console.log(acc.getId());
                    if(filetype == 'PDF'){
                      acc.set('S3_PDF__c', s3url);
                    }
                    else{
                        acc.set('S3_Image__c', s3url);
                    }

                    org.update({ sobject: acc }).then( result => {
                        console.log(result);
                        return result;
                    }).catch(error => {
                        console.log('Error: ', error.message);
                    });                
                  }                  
            });
            });            
        }
| improve this answer | |

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.