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
TraceyTracey 

Update a field value with a new custom button

Could somebody please let me how I can update field value with the use of a custom button?
 
 
Best Answer chosen by Admin (Salesforce Developers) 
mromanimromani

That really helps but i'm not reffering to something in the Customize->lead area.

I have a a created object named Box. Box has 2 fields, Box_Name and Box_Count.

What do i need to change in the javascript you provided to allow me to update (change) the Box_Count field?

 

i tried this but it didnt work:

 

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

var box= new sforce.SObject("{Box__c}");
box.Box_Count = "{!Box__c.Box_Count__c } +1";

var result = sforce.connection.update([box]);

if (result[0].getBoolean("success"))
{
    // Refresh window   window.location.reload();
     alert("Succes");

}
else
{
    alert("Error saving lead");
}

 

 

any help would be great!

thanks

All Answers

tlohrbeertlohrbeer
I just figured out a way to do this by doing the following:

 - Create a custom button (I did this under App Setup > Customize > Leads > Buttons and Links)
 - For Behavior select "Execute JavaScript"
 - For Content Source select "OnClick JavaScript"
 - For the JavaScript, enter the following:

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

var lead = new sforce.SObject("Lead");
lead.id = "{!Lead.Id}";
lead.OwnerId = "<hardcoded user id>";

var result = sforce.connection.update([lead]);

if (result[0].getBoolean("success"))
{
    // Refresh window
    window.location.reload();
}
else
{
    alert("Error saving lead");
}

In this case all I'm doing is changing the owner of the lead. I hardcoded the ID because I didn't know how to look it up. However, you can change other lead fields as well.  You can find the API docs at http://www.salesforce.com/us/developer/docs/api/index.htm that tell you all the fields you can use.
mromanimromani

That really helps but i'm not reffering to something in the Customize->lead area.

I have a a created object named Box. Box has 2 fields, Box_Name and Box_Count.

What do i need to change in the javascript you provided to allow me to update (change) the Box_Count field?

 

i tried this but it didnt work:

 

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

var box= new sforce.SObject("{Box__c}");
box.Box_Count = "{!Box__c.Box_Count__c } +1";

var result = sforce.connection.update([box]);

if (result[0].getBoolean("success"))
{
    // Refresh window   window.location.reload();
     alert("Succes");

}
else
{
    alert("Error saving lead");
}

 

 

any help would be great!

thanks

This was selected as the best answer
max4904max4904

Did you ever get this to work? If so, what was the trick? I have a similar problem I am trying to figure out and need some help. Thanks!

ctomeyctomey

I tried what tlohbeer suggested to change the owner of a lead but keep getting the error "Lead is not defined". Any suggestions out there?