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

Custom Button to Change Status and Completed Date

I created a custom button on a custom object and onclick, it should update the status to 'Completed' and the Completed date to NOW().  I tested it in Sandbox and it worked properly, I updated the field id's to Production and it worked the day I deployed it.  However it has not worked since I initially deployed it. 

Here are the details:

Detail Page Button

Behavior: Display in existing Window without Sidebar or Header
Content Source: URL


Link Encoding: Unicode (UTF-8)

The only other thing I've found online suggested changing the &save=1 to &save=0, but neither option has worked for me.


Then based on feedback I received in the Answers Community, I tried modifiying the code to some javascript so it would envoke onclick.  Every time I click on the button, I receive an error message saying 'Object Expected'.  Here is the code I'm using:



var sr = new sforce.SObject("Setup_Request__c"); = "{!Setup_Request__c.Id}";
sr.Status__c = 'Completed';
sr.Completed_Date__c = new Date();
result = sforce.connection.update([sr]);



Any help is greatly appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

This variables highlighted below is nothing but the HTML values of that fields.

Ensure once if its same.



However the javascript code you mentioned is appropriate,

Have made some minor changes, check if it helps:



var sr = new sforce.SObject("Setup_Request__c"); 
sr.Id = "{!Setup_Request__c.Id}"; 
sr.Status__c = 'Completed'; 
sr.Completed_Date__c = new Date(); 
result = sforce.connection.update([sr]);