2

I am trying to update a field on a record using an OnClick Javascript button. It seems to be updating the record but when I refresh the page nothing shows. What am I doing wrong?

Below is my code:

{!requireScript("/soap/ajax/34.0/connection.js")}

var jobRequisition = new sforce.SObject("Job_Requisition__c");
jobRequisition.Id = "{!Job_Requisition__c.Id}";
jobRequisition.requisition__c = 'Something';

var result = sforce.connection.update([jobRequisition]);
window.location.reload();

When I check the result I get this error:

{errors:{fields:'Id', message:'Record ID: id value of incorrect type: 559e1e161ef6752dff2ff0f1', statusCode:'MALFORMED_ID', }, id:null, success:'false', }

I have a field called id__c with the "559e1e161ef6752dff2ff0f1" value, but I specified jobRequisition.Idin the above code so I do not understand why it is referencing that. I believe this should be the salesforce Id not my custom field

9
  • Have you checked the result for success?
    – Saroj Bera
    Sep 21, 2015 at 6:46
  • I have, please take a look at the update Sep 21, 2015 at 7:04
  • What is the value of {!Job_Requisition__c.Id} on line three?
    – Rob
    Sep 21, 2015 at 7:45
  • I couldn't see any issues, it should work. Please check if this same code is there in your Org.
    – Saroj Bera
    Sep 21, 2015 at 7:46
  • @Rob I get "undefined" when I try display the value of the Id field in an alert. Sep 21, 2015 at 8:15

1 Answer 1

0

Here is an example of Salesforce Ajax toolkit implementation. I am creating an Account then updating it and again retrieving the updated account. You can see all the details in the browser console.

It is a standalone page you can check and compare with your code.

<apex:page showHeader="true" sidebar="true">
    <script type="text/javascript">
        var __sfdcSessionId = '{!GETSESSIONID()}';
    </script>
    <script src="../../soap/ajax/34.0/connection.js" type="text/javascript"></script>
    <script type="text/javascript">
        //create an account
        var account = new sforce.SObject("Account");
        account.Name = "myName";
        result = sforce.connection.create([account]);

        //update that account
        account.id = result[0].id;
        account.Phone = "1234567890";
        result = sforce.connection.update([account]);
        console.log("result" +result);

        //Retrieving the account
        var qRresult;
        if (result[0].getBoolean("success")) {
          console.log("account with id " + result[0].id + " updated");
          qRresult = sforce.connection.retrieve("Name,Phone", "Account", [result[0].id]);
          console.log("result" +qRresult);
          console.log("result" +qRresult[0].Phone);
        } else {
          console.log("failed to update account " + result[0]);
        }   
    </script>    
</apex:page>
2
  • is the account.id the salesforce Id or is it a custom field you named id (id__c) Sep 22, 2015 at 11:22
  • account.id the salesforce Id Id not the custom Id.
    – Saroj Bera
    Sep 22, 2015 at 15:35

You must log in to answer this question.

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