You need to sign in to do that
Don't have an account?
KC0798
rec[0].Mood__c = "Happy";
var saveResult = sforce.connection.update(rec);
if(saveResult[0].success){ // Always indicates success
alert('Successful');
}
else {
alert('There was an error');
}
Simple update not working
Hi there,
I'm writing a simple code to update my custom 'Mood' field on the user record. The result is successful, but the record is not updated. The mood field is a picklist. Anyone? Code below:
var result = sforce.connection.query("SELECT Id, Name, Mood__c " +
"FROM User WHERE Id='{!User.Id}'");
var rec = result.getArray("records");
alert(rec[0].Mood__c); //Testing with first record. Confirmed that a record is retrieved and show initial record value
"FROM User WHERE Id='{!User.Id}'");
var rec = result.getArray("records");
alert(rec[0].Mood__c); //Testing with first record. Confirmed that a record is retrieved and show initial record value
rec[0].Mood__c = "Happy";
var saveResult = sforce.connection.update(rec);
if(saveResult[0].success){ // Always indicates success
alert('Successful');
}
else {
alert('There was an error');
}
Many Thanks!
KC
werewolf
This is Javascript, btw, should be posted on the AJAX board. Anyway:
Why not output what the error actually is rather than just alerting "there is an error!"? That will probably be very helpful to you in debugging the issue.
Docs here:
http://www.salesforce.com/us/developer/docs/ajax/Content/sforce_api_ajax_errors.htm#kanchor53
KC0798
Thanks and you're right, sorry abt that!
KC0798
I tried to capture the error, but the problem is that its not returning any error. It seems to be going thru, but the record is just not updated.
I can query the record fine and I'm just updating one field, could it be the fields that I'm querying? Do I need to query specific fields or number of fields before I can update it back?
werewolf
In the results that come back, each individual result will also contain an array of error messages, probably called errors. There is very likely an error message there.
Another option is to turn on debug logging and then do what you're trying to do. That will tell you where you went wrong too.
Finally, in general when developing with the AJAX toolkit, it's a good idea to use Firebug. That would allow you to just put a breakpoint after your update and examine the results. It will probably tell you exactly what you need to know.