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
anil87anil87 

change lead owner through a custom button in search results page

Hi,

 

We like to have a Custom Lead Accept button which would be used on the Search Results Page.

 

When the user selects the Leads and clicks the button, it should assign the Lead ownership to the Person who clicked the button.how i can achieve this any help appriciate greatly

Best Answer chosen by Admin (Salesforce Developers) 
Vinit_KumarVinit_Kumar

Hey Anil,

 

Try below code :-

 

{!REQUIRESCRIPT ("/soap/ajax/24.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Lead)};
var newRecords = [];
if (records[0] == null) {
alert("Please select at least one row")
}
else {
for (var n=0; n<records.length; n++) {
var c = new sforce.SObject("Lead");
c.id = records[n];
c.OwnerId ="{!$User.Id}";

newRecords.push(c);
}
result = sforce.connection.update(newRecords);
window.location.reload();
}

All Answers

Vinit_KumarVinit_Kumar

Hey Anil,

 

Try below code :-

 

{!REQUIRESCRIPT ("/soap/ajax/24.0/connection.js")}
var records = {!GETRECORDIDS($ObjectType.Lead)};
var newRecords = [];
if (records[0] == null) {
alert("Please select at least one row")
}
else {
for (var n=0; n<records.length; n++) {
var c = new sforce.SObject("Lead");
c.id = records[n];
c.OwnerId ="{!$User.Id}";

newRecords.push(c);
}
result = sforce.connection.update(newRecords);
window.location.reload();
}

This was selected as the best answer
anil87anil87

Hi Vineet,

Now i want to Modify the Accept lead Button:
 
When the User Selects the Lead using the custom button - it should re-direct to the Lead Page.
 
If multiple Leads are selected then - it should re-direct to the First Lead selected or maybe remain on the current screen.
Salesforce ServiceSalesforce Service
Hi, where you ever able to figure out the re-direct?