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
VSK98VSK98 

Can anybody pls share the sample code for Selected list view from javascript using button

Hi All,

Can anybody pls share the sample code for Selected list view from javascript using list view button
Waqar Hussain SFWaqar Hussain SF
can you please explain
VSK98VSK98
I have created one list view button & crerated list view.....In list view 10 records are available...I selected 5 out of 10 , when i click the button only 5 records status should be change
I hope it will give clear

Feel free to ask again 
Adv thnx
Siv
naga raju 19naga raju 19
I have one requirement that is create a custom button on Leads List View, once the user clicks on that button the selected leads should update with lead status as Unqualified.

For this i created one list view button with Execute JavaScript and place it in Search Layouts (Leads Listview).

Step1:

Go to leads ==> Click on Buttons,Links and Actions ==> Click on New Button or Link.


JavaScript Code to paste in the Window.

//adds the proper code for inclusion of AJAX toolkit
{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
//string for the URL of the current page
var url = parent.location.href; 
//grabs the Lead records that the user is requesting to update
var records = {!GETRECORDIDS($ObjectType.Lead)}; 
//array for holding records that this code will ultimately update
var updateRecords = []; 
 //if the button was clicked but there was no record selected
if (records[0] == null) {
        //alert the user that they didn't make a selection 

alert("Please select at least one record to update."); 
} else { //otherwise, there was a record selection
for (var a=0; a<records.length; a++) { //for all records
//create a new sObject for storing updated record details
var update_Lead = new sforce.SObject("Lead"); 
//set the Id of the selected Lead record
update_Lead.Id = records[a]; 
 //set the value for Status to 'Unqualified'
update_Lead.Status = "Unqualified";
updateRecords.push(update_Lead); 
//add the updated record to our array
}
 //push the updated records back to Salesforce
result = sforce.connection.update(updateRecords);
parent.location.href = url; //refresh the page

}


Step 2 :

Click on Save.

Step 3: 

Go to Leads Object==> Search  Layouts==>Edit Leads List View==>Select the Newly created list view button and save.

Step 4: 

select the Lead you want to update and click on the Button. Then selected Leads were updated with Unqualified  Status...
 
naga raju 19naga raju 19
plz give replay if this code is seful to you .bye