+ Start a Discussion
Heath AbbateHeath Abbate 

Create buttons to change owner of lead without going thru wizard.

Newbie that needs help.  For leads we have an "unassigned" queue.  From that queue out of the box as you all know we can check the check box next to the leads and then hit change owner which takes you to a new page to choose the new owner and then you hit ok and it changes the owner.  I want to streamline that so we check the box next to the leads and then hit a button with the salespersons name on it and it magically changes the owner to that sales person.  I am assuming from my limited knowledge I could do this with a custom button that executes OnClickJavaScript.   Problem is I have zero idea how to write the needed Javascript.  Can anybody assist?
The below script will get you started.
{!REQUIRESCRIPT ("/soap/ajax/33.0/connection.js")} 

var selectedLeadIds = {!GETRECORDIDS($ObjectType.Lead)}; 
var updLeads = new Array(); 

for(var i = 0; i < selectedLeadIds.length; i++){ 
var l = new sforce.SObject("Lead"); 
l.Id = selectedLeadIds[i]; 
l.OwnerId = '<replace with User Id of the intended Owner>'

var updRes = sforce.connection.update(updLeads); 

alert('Update Successful'); 

alert('Error: ' + updRes[0]); 

Heath AbbateHeath Abbate
Awesome!  I will give this a try today.  
Heath AbbateHeath Abbate
You da man!  Works perfectly.  Thank you Terence!
Heath AbbateHeath Abbate
Terrence is there a way at the end of the script for it to refresh the page so the leads who's owner was changed disappear from the list.  right now we have to hit refresh to clear up the view.  thanks in advance.
Heath AbbateHeath Abbate
does anybody know how I add code so that this also emails the new owner a notification as it does when you tick that box using the standard assignment buttons?