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
miteshsuramiteshsura 

How to use checkbox available on related list?

Hi,

 

While creating a list button, it asks me "Display Checkboxes (for Multi-Record Selection)" ? May I know how do I take advantage of it in my custom list button?

 

Selecting the option does show checkbox next to each line item in the related list, but thats about it. I want to take action only on selected records, how can I do it? 

 

Any idea, reference? 

 

Thanks. 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

There's a formula called "GETRECORDIDS" that you use to return a JavaScript array of records by their ID values.

 

It's used like this:

 

var selectedOpportunityIds = {!GETRECORDIDS($ObjectType.Opportunity)}
if(selectedOpportunityIds.length<1) {
  alert('Please select at least one record before clicking this button!')
  return
}
// Do something with the ID values here.

Note there are no quotes around the merge field, since it's going to eventually become a JavaScript function call that returns an array of selected indices. Also, the selected records can be passed as values to a Visualforce page.

 

Use the "Display Checkboxes" option when you intend to use GETRECORDIDS or a Visualforce page that accepts selections, otherwise, you should not use the option. Salesforce.com dynamically chooses to display checkboxes by determining if any buttons currently configured for that related list on the current page layout have this feature checked.

 

EDIT: I meant to say, it will return an array of selected ID values. This means the array will be something like { '006XXXX...', '006XYYY...' }.

All Answers

sfdcfoxsfdcfox

There's a formula called "GETRECORDIDS" that you use to return a JavaScript array of records by their ID values.

 

It's used like this:

 

var selectedOpportunityIds = {!GETRECORDIDS($ObjectType.Opportunity)}
if(selectedOpportunityIds.length<1) {
  alert('Please select at least one record before clicking this button!')
  return
}
// Do something with the ID values here.

Note there are no quotes around the merge field, since it's going to eventually become a JavaScript function call that returns an array of selected indices. Also, the selected records can be passed as values to a Visualforce page.

 

Use the "Display Checkboxes" option when you intend to use GETRECORDIDS or a Visualforce page that accepts selections, otherwise, you should not use the option. Salesforce.com dynamically chooses to display checkboxes by determining if any buttons currently configured for that related list on the current page layout have this feature checked.

 

EDIT: I meant to say, it will return an array of selected ID values. This means the array will be something like { '006XXXX...', '006XYYY...' }.

This was selected as the best answer
mk2013mk2013


I have a question regarding custome button on a related list. My related list uses custome object SampleObj__c.
This object has field like name, distict etc and of course id.
If I need to get the name of the selcted object how do I get that in javascript?
I have tried so many ways but I keep getting syntax error or javascript error.
I am a newbie to salesforce and trying to get this working. Appreciate your help.

 

Thanks,

mk2013

Silabs AdminSilabs Admin

mk2013,

What does your code like?

 

You can try something like below. I have not tried it, you may wnat to have some alert dialogs. 

 

{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} 
var selectedOpportunityIds = {!GETRECORDIDS($ObjectType.SampleObj__c)}

if(selectedOpportunityIds.length == 1) {
  result = sforce.connection.query("SELECT Name FROM SampleObj__c WHERE Id=selectedOpportunityIds );
  records = result.getArray("records");
}

 

 

mk2013mk2013

Hello,

thanks for your suggestion.

I tried it and it worked. The only problem I have now is how to extract the string value of name from that record? 

 

I am copying my code here.

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

var records = {!GETRECORDIDS($ObjectType.Encompass_Quote__c)};
alert("Record Selected " + records[0]);


if(records[0] ==null){
     alert("Please select at least one row to mark primary");
}else if(records.length > 1){

     alert("Please select only one row to mark as primary");
}else{

     if(records.length == 1) {
         result = sforce.connection.query("SELECT Name FROM Encompass_Quote__c WHERE Id='"+ records[0] +"'");
        records = result.getArray("records");
        var name = records[0];
       alert("Record Name " +name);
}

 

}

With the above code in alert box. I get name value as below.

 Record Name  {type:'Encompass_Quote__c', Id:null, Name:'368286', }

 

I just need the string 368286, now do you retrieve that? I know it's a very basic question, but when I try record[0].name I get undefined.

 

Thanks,

mk2013

 

 

Silabs AdminSilabs Admin
What do you see in alert? You may have to use JS methods to get the exact value.
mk2013mk2013

Got it. I was referring to it as lowercase 'name' instaed of 'Name', so I got undefined. Follwoing code gives me correct value.

 

var name = records[0].name

 alert("Record Name " +name);

Thanks,

mk2013