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
rtrevo915rtrevo915 

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

/{Setup_Request__c.Id}/e?retURL={Setup_Request__c.Id}&00N70000002jHJ9={!NOW()}&00N70000002jHKl=Completed&save=1

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:

 

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

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]);

window.location.reload();

 

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.

/{Setup_Request__c.Id}/e?retURL={Setup_Request__c.Id}&00N70000002jHJ9={!NOW()}&00N70000002jHKl=Completed&save=1

 

However the javascript code you mentioned is appropriate,

Have made some minor changes, check if it helps:

 

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

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]); 

location.reload(true);