function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
blackbirdblackbird 

How to do simple update of records

Hi I am pretty new @ this, can anyone show me a complete simple record update script in AJAX.  I have tried on my own by using examples from the apex_ajax.pdf but I keep getting errors. I am able to do a query but my updating does not seem to be properly syntaxed.
Please help, thx in advance
RickyGRickyG
Not sure where the problem is, but check out the API documentation.  You update a record with an update call for the SObject.

Hope this helps.
Greg HGreg H
In updates you need to pass the id of the record you want to update in addition to any fields you'll be updating.  The bext reference for all of this is the API or AJAX documentation but hopefully this little snippet can assist too:
Code:
var _Account = new sforce.SObject("Account"); //create an sObject for an object - here we are using account but it could be anything
_Account.Id = id; //id should be gathered from a query or something earlier in the script - you'll need the id of the record you want to update though
_Account.Name = "This Name is Changed"; //you can hard code a value or pass something dynamically (can be any field) - here we are hard coding an update to the account name
var updateAccount = sforce.connection.update([_Account]); //actually perform the update to the record
if (updateAccount[0].getBoolean("success")) { //check that the update was successful
   alert("Updated account: "+updateAccount[0].id); //alert success notification
} else { //otherwise unsuccessful
   alert("API error: "+updateAccount[0]); //alert response from update attempt
}

 
Good luck,
-greg