0

I'm using the following javascript code to unlock an Opportunity object.

Opportunity.PoSa_Platform_Provider__c}{!requireScript("/soap/ajax/25.0/connection.js")}

//Get the URL String
var recordURL = document.URL;
var URLlength = recordURL.length;

//Get the record ID from the URL.
//Id length of Opportunity object is 15
var recordId = recordURL.substring((URLlength - 15), URLlength);
alert("recordId: " + recordId);

//Assuming the name of the locked field is locked__c
var opp = new sforce.SObject("Opportunity");
alert("opp: " + opp);
opp.id = "0067E000003p5ey";
opp.IsPrivate = false;
var result1 = sforce.connection.create([opp]);

if (result1[0].getBoolean("success")) {
alert("Updated the locked field value to " + result1[0].locked__c);
} else {
alert("failed to update " + result1[0]);
} 

but I get the following message: "failed to update {errors:{fields:'id', message:'can not specify Id in an insert call', StatusCode:'INVALID_FIELD_FOR_INSERT_UPDATE'}'id:null, success:'false'}"

Could you please advise why it is not possible to update the id field in the javascript code?

closed as unclear what you're asking by Sebastian Kessel, Vigneshwaran G, Boris Bachovski, Mohith Shrivastava, Ralph Callaway Oct 21 '16 at 0:24

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Why have you edited out your code? – Dave Humm Oct 20 '16 at 17:57
1

Id is a Salesforce native field and it is not updateable. We can't change Id value and we can't update them as well. They are read only for end user.

Every ID in the App is either 15 characters or 18 characters (API). The first 3-digits of the ID are always the Entity ID which can be used to determine the type of the entity. Below is the Entity ID mapping. To use it, get the first 3-digits of the ID and look-up the Entity name in the following table.

For example, for ID: 00D000000000062, you need to lookup "00D" in the table below, which will indicate that it's an Organization ID.

Below is an example of a Contact ID (003D0000001aH2A) on NA1 which has server ID 'D':

003 D0 000001aH2A

Object ID Prefix Server ID Identifier

Reference Standard Field Record ID Prefix Decoder

0

You just replace this line

var result1 = sforce.connection.create([opp]);

into

var result1 = sforce.connection.update([opp]);

When If you have an record Id. you should take update method. Don't try to create method because salesforce Id field is a standard and system generated field. we only have a view permission. It doesn't updatable field in salesforce.

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