0

I've written simple code to update field on object by using javascript custom button, but it throwing Error. The code is ;

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

 var o = new sforce.SObject("Student__c");
 o.id = "{{!Student__c.Id}}";
 alert(o.id)
 o.Laptop__c = true; 
 result =sforce.connection.update([o]);

if (result[0].getBoolean("success")) {
alert("record with id " + result[0].id + " updated");
 } else {
alert("failed to update " + result[0]);
}

window.location.reload();

but it throwing error like

failed to update {errors:{fields:'Id', message:'Record ID: id value of incorrect type: {a012800000XluCo}', statusCode:'MALFORMED_ID', }, id:null, success:'false', }

what is wrong here, why it throwing error

0

1 Answer 1

2

You have double {} in your code, try this:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

 var o = new sforce.SObject("Student__c");
 //removed the excess {}     
 o.id = "{!Student__c.Id}";
 alert(o.id)
 o.Laptop__c = true; 
 result =sforce.connection.update([o]);

if (result[0].getBoolean("success")) {
alert("record with id " + result[0].id + " updated");
 } else {
alert("failed to update " + result[0]);
}

window.location.reload();
1
  • this is ok now. my field is read only from page layout. and this code is working fine for Admin. when i'm trying for non-admin it again throws same error why??
    – user29314
    Jul 21, 2016 at 6:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .