+ Start a Discussion
Shamrock SnowmanShamrock Snowman 

Need Custom Button that updates a field in my object

I am hoping for some code that I can use in a Custom Button.  It is for the Detail Page of a custom object called Orders.  I have a text field called Recruiter In Charge, and I want to have that field automatically filled in with the user's name (first and last) when he clicks the Button on the Detail Page.

 

Any help would be greatly appreciated!

 

 

Best Answer chosen by Admin (Salesforce Developers) 
crop1645crop1645
{!requireScript("/soap/ajax/24.0/connection.js")} 
var lead = new sforce.SObject("Lead"); 
lead.Id = "{!Lead.Id}"; 
lead.Status = "Contacted"; 
result = sforce.connection.update([lead]); 

 The above is a Custom Button Javascript on Lead that updates the status to Contacted when clicked. You can adapt this to Orders__c and use the merge fields $User to get first and last name into your Orders__c object

All Answers

crop1645crop1645
{!requireScript("/soap/ajax/24.0/connection.js")} 
var lead = new sforce.SObject("Lead"); 
lead.Id = "{!Lead.Id}"; 
lead.Status = "Contacted"; 
result = sforce.connection.update([lead]); 

 The above is a Custom Button Javascript on Lead that updates the status to Contacted when clicked. You can adapt this to Orders__c and use the merge fields $User to get first and last name into your Orders__c object

This was selected as the best answer
Shamrock SnowmanShamrock Snowman

Thanks, Eric.

Please forgive my code ignorance, but I tried several different strategies of inserting my fields and objects into this script, from sandbox to production, and every time I received a "syntax error" message when clicking on the button.

 

Finally, I tried just pasting your whole code into an identical button on my own Leads object, and I still got the error.  Any idea what I may be doing wrong?

 

Dave

crop1645crop1645

Sorry Shamrock -- that's what I get when I cut/paste and remove unnecessary statements for clarity. My error. I corrected the script in the post above  - there was a trailing '}' that shouldn't have been there

Shamrock SnowmanShamrock Snowman

Thank you very much!  That worked!

 

Dave