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>";
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.
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
- 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.
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
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!
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?