1

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.

5
  • can you please post some code here so that its clear why we need to update through REST API? Commented Oct 7, 2013 at 10:49
  • Can you say why you want to use the REST API?
    – greenstork
    Commented Oct 7, 2013 at 13:37
  • JavaScript remoting (@RemoteAction method in the controller) would be the appropriate way to go, I think: salesforce.com/us/developer/docs/pages/Content/…
    – metadaddy
    Commented Oct 7, 2013 at 16:36
  • @metadaddy So can JS Remoting controllers be called from Custom Button JavaScript? Commented Nov 7, 2013 at 0:47
  • @AndrewFawcett - yes - you can put the RemoteAction method in a controller extension.
    – metadaddy
    Commented Nov 7, 2013 at 3:41

1 Answer 1

1
    <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

You must log in to answer this question.

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