How to update a single record in VF page using REST API on click of a button?
The requirement is to update an account status on click of a button. I dont want to use apex controller . Want to do it using javascript so thought of rest api.
How to update a single record in VF page using REST API on click of a button?
The requirement is to update an account status on click of a button. I dont want to use apex controller . Want to do it using javascript so thought of rest api.
<script src="/soap/ajax/29.0/connection.js"></script>
<script>
var contactId = "{!Contact_ID}";
function initPage() {
try{
var contact = sforce.connection.retrieve("Phone",[contactId])[0];
contact.Phone = "12398238";
result = sforce.connection.update([account]);
if (result[0].getBoolean("success")) {
log("account with id " + result[0].id + " updated");
} else {
log("failed to update account " + result[0]);
}
}
}
</script>
Please follow the above for how to approach using purely java script.Note with ajaz toolkit you don't need REST API at all .
I don't recommend using JavaScript or ajax toolkit for this requirement or using any REST API .A simple visualforce page with an extension controller would do the needful