1

I have a few custom buttons that we place on our page layouts that are Javascript buttons. These update a few fields on the record. I successfully created some but I am having an issue with the last one not updating records. Any ideas what I could be doing wrong on the button that isn't working? By not working, I mean the records aren't getting updated. I ruled out a workflow stopping it because I essentially created the exact same code in Apex and had it execute anonymously in order to get the same effect and it was successful.

Not working button:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 

if (('{!Fee_Adjustment__c.Supervisor_Comments__c}' === '' || '{!Fee_Adjustment__c.Supervisor_Comments__c}' === 'null') && ('{!Fee_Adjustment__c.Reviewer_Notes__c}' === '' || '{!Fee_Adjustment__c.Reviewer_Notes__c}' === 'null'))
{
  alert('Reviewer or Manager notes required.');
} else
{
  //identify the record
  var adjustment = new sforce.SObject("Fee_Adjustment__c");
  adjustment.Id = "{!Fee_Adjustment__c.Id}";

  //make the field change
  adjustment.OwnerId = "{!Fee_Adjustment__c.Originator__c}";
  adjustment.Status__c = 'Pending';
  adjustment.Status_Detail__c = 'Originator';

  //save the change
  sforce.connection.update([adjustment]);

  //refresh the page
  window.location.reload();
}

Working button:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}

var assessed = parseFloat('{!Fee_Adjustment__c.Total_Fees_Assessed__c}'.replace('$', ''));
var desired = parseFloat('{!Fee_Adjustment__c.Total_Fees_Desired__c}'.replace('$', ''));

if (assessed == 0 || assessed == desired)
{
  alert('Fees must be entered in Detail before submitting adjustment request');
} else
{
  // identify the record
  var adjustment = new sforce.SObject("Fee_Adjustment__c");
  adjustment.Id = "{!Fee_Adjustment__c.Id}";

  // make the field change
  adjustment.OwnerId = "{!Fee_Adjustment__c.SupervisorId__c}";
  adjustment.Status__c = 'Pending';
  adjustment.Status_Detail__c = 'Supervisor';

  // save the change
  sforce.connection.update([adjustment]);

  //refresh the page
  window.location.reload();
}
1

Are you getting some errors or the button just click refreshes the page with no updates?

Also check if the last modified data gets updated even though there is no field changes. Try adding:

result = sforce.connection.update([adjustment]);
if (result[0].getBoolean("success")) {
    log("account with id " + result[0].id + " updated");
  } else {
    log("failed to update account " + result[0]);
  }
  • Perfect. It told me that there was an error updating the Account. Originator__c needed changed to OriginatorId__c. I guess the field returns the Name instead of Id of the record. – dphil Jun 6 '14 at 20:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.