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
KunlunKunlun 

Is it possible to add checkbox in related list like list view.

In list view we can multiple select the checkbox and click button to do some operation.
Can I add this checkbox in related list? and do same operation like list view?
sfdcfoxsfdcfox
When creating list buttons, an option appears to add check boxes to the list. If your button is added to a list view, it will create the boxes automatically.
KunlunKunlun
I can add this button in list view, but I can't add it in related list
jpizzalajpizzala
To add the checkboxes to a related list for a custom button do the following:

  1. Edit the Custom Button or Link (Setup -> [App Setup] Customize -> Object -> Buttons and Links)
  2. Make sure List Button is selected
  3. Check the Display Checkboxes (for Multi-Record Selection) option after selecting List Button
That should do it.
MayankAdmMayankAdm

Hi Justin,

I need to use this functionality but in my case custom button link to visualforce page and when user selected records from related list the selected ids from checkbox should pass  to visualforce page (which is linked to button) 

How this things should be implemented

Please Help me out this problem

Thanks

 

Sagar Nagvekar 14Sagar Nagvekar 14
<!--
  This VF page will list tasks owned by a user in list view. Checking checkboxes on left hand side of tasks will
  assign those tasks to current user after he clicks on "Change ownership to me".
  Thus this will function like a queue for tasks. Any user can take ownership of any task.
-->
<apex:page controller="TestTakeOwnership">
  <apex:form >
    <apex:pageMessages />
    <script>
      var flag=0;
      var SelectConId1='';
      
      // for success message show from javascript itself
      var flag2 = 0;

      // total count of checkboxes visible
      var countchbox=0;

      function checkAll(cb)
      {
         //alert('All checkboxes have been checked or unchecked');
         flag=0;

         // List of IDs of the tasks. Comma separated.
         SelectConId1='';

         var inputElem = document.getElementsByTagName("input");

         for(var i=1; i<inputElem.length; i++)
         {
            if(inputElem[i].id.indexOf("checkedone")!=-1)
            {
               inputElem[i].checked = cb.checked;
               flag=flag+1;
               SelectConId1=SelectConId1+inputElem[i].name+',';
            }
         }
         //alert('Check all main checkbox checked. flag value is ' + flag);
         
         if(cb.checked!=true)
         {
            //alert('main checkbox is unchecked');
            SelectConId1="";
            flag=0;
         }
         //alert(SelectConId1);
      } 
      
      function checkone(cb)
      {
          //alert('One checkbox is checked or unchecked');
          
          countchbox=0;
    
          if(cb.checked)
          {  
              flag=flag+1;
              //alert('now flag is ' + flag);
              //alert('now SelectConId1.length is ' + SelectConId1.length);
              
              if((SelectConId1.length)<=1)
              {
                  SelectConId1=cb.name+',';
              }
              else
              {
                  SelectConId1=SelectConId1+cb.name+',';                  
              }
          }
          else if((cb.checked)!=true)
          {
              //alert('cb.checked is false');
              flag=flag-1;
              //alert('checkbox unchecked, after decrementing flag value is ' + flag);
              if((SelectConId1.length)<=1)
              {
                  SelectConId1=cb.name+',';
              }
              else
              {
                  var allids=SelectConId1.split(',');
                  var idarray='';
                  for(var i=0;i<allids.length;i++)
                  {
                      if(allids[i]!=cb.name  && allids[i]!='')
                      {
                          //alert('this id wont be removed');
                          idarray=idarray+allids[i]+',';
                      }
                      else
                      {
                          //alert('removing this id as match found');
                          if(allids[i] == cb.name)
                          {
                              //alert('Removing this id as match found');
                          }
                          
                          if(allids[i] == '')
                          {
                              //alert('removing blank');
                          }
                          
                      }
                  }
                  SelectConId1=idarray;
              }
          }
     
          var inputElem = document.getElementsByTagName("input");
          
          for(var i=0; i<inputElem.length; i++)
          {
              if(inputElem[i].id.indexOf("checkedone")!=-1)
              {
                  // Counting total number of checkboxes  
                  countchbox=countchbox+1;                               
              }
          }
          //alert('Total number of checkboxes countchbox is ' + countchbox);
          //alert('flag value is ' + flag);
                  
          if(flag==countchbox)
          {
              //alert('flag is equal to countchbox');
              document.getElementById("main").checked=true;
              //alert('last checkbox is checked, so checkAll auto check doing');
          }
          else
          {
              //alert('flag is not equal to countchbox');
              document.getElementById("main").checked=false;
              //alert('last checkbox is not checked, so checkAll uncheck');
          }
          //alert(SelectConId1);
      }
      
      function chngeOwner()
      {
          //alert('chngeOwner called');
          if((SelectConId1.length)<=1)
          {
              alert('Please select at least one task to change its ownership to you');
          }
          else
          {
              //alert('Some task has been selected, so proceeding, SelectConId1 is ' + SelectConId1);
          
              // for success message show from javascript itself
              flag2 = flag;
              
              //alert('some ownership changing, so making flag 0, counting begin again');
              flag = 0;
          
              if(flag2 == 1)
              {
                  alert(flag2 + ' task will be assigned to you.');
              }
              else
              {
                  alert(flag2 + ' tasks will be assigned to you.');
              }
          
              paraFunction(SelectConId1); 
          }
          
          // Reset the counter
          SelectConId1 = '';
      }
    </script>
    
    <apex:outputPanel id="displayCountPanel1">
      Total number of tasks in this queue: <apex:outputLabel value="{!totalCount}"/>
    </apex:outputPanel>

    <br/>    
  
    <!--
      chngeOwner() is the javascript function
    -->
    <apex:commandButton value="Change ownership to me" onclick="chngeOwner()" reRender="outputTable, displayCountPanel1" status="counterStatus"/>
 
    <apex:actionStatus startText=" (Processing...)" stopText="" id="counterStatus"/>
    
    <br/> <br/>
    
    <apex:outputPanel >
      Select the checkboxes below for the tasks you would like to take ownership of and then click on the button "Change ownership to me"
    </apex:outputPanel>

    <apex:pageBlock id="outputTable">
      <apex:pageBlockTable value="{!tasksOwnedByQueue}" var="t">
        <apex:column >
          <apex:facet name="header">
            <input type="checkbox" id="main" onclick="return checkAll(this)"/>
          </apex:facet>
          <input type="checkbox" name="{!t.id}" id="checkedone" onclick="return checkone(this)"/>
        </apex:column>
      
        <div id="{!t.id}">
          <apex:column headerValue="Task ID" value="{!t.id}"/>
          <apex:column headerValue="Subject" value="{!t.subject}"/>
          <apex:column headerValue="Related to" value="{!t.whatid}"/>
          <apex:column headerValue="Related to name" value="{!t.whoid}"/>
          <apex:column headerValue="Status" value="{!t.status}"/>
        </div>
      </apex:pageBlockTable>
      Total number of tasks in this queue: <apex:outputLabel value="{!totalCount}"/>
    </apex:pageBlock>
    
    <!--
      changeOwnership() is the function in the controller class :- TestTakeOwnership
    -->
    <apex:actionFunction name="paraFunction" action="{!changeOwnership}" reRender="outputTable, displayCountPanel1">    
      <apex:param id="anode" name="node" value="" />
    </apex:actionFunction>
  </apex:form>
</apex:page>

/*
   The controller class
*/
public class TestTakeOwnership
{
    private list<task> tasksOwnedByQueue = new list<task>();
    public integer totalCount {get;set;}
    User u;
    
    public TestTakeOwnership()
    {
        u = [select id, name from user where name = 'John Connor'];
        tasksOwnedByQueue = [select id, subject, status, whatid, whoid from task where ownerid = :u.id and status != 'Completed'];
        totalCount = tasksOwnedByQueue.size();
        System.debug('//////////////////constructor code executes - total number of tasks is ' + totalCount);    
    }
    
    public list<task> getTasksOwnedByQueue()
    {
        return tasksOwnedByQueue;
    }
    
    public void changeOwnership()
    { 
        String para = Apexpages.currentPage().getParameters().get('node');
        System.debug('======================= ' + para);
  
        list<id> changeOwnershipOfTheseTasks = para.split(',');
  
        System.debug('////////////////////list of tasks is ' + changeOwnershipOfTheseTasks);
        System.debug('////////////////////Number of tasks identified is ' + changeOwnershipOfTheseTasks.size());
        
        list<task> modifyTasks = [select id, subject from Task where id in :changeOwnershipOfTheseTasks];
        
        totalCount = tasksOwnedByQueue.size();
        System.debug('//////////////////before changing ownership :- total number of tasks in queue is ' + totalCount);
        
        try
        {
            System.debug('////////////////Current user id is - ' + UserInfo.getUserId());
            String currentUserId = UserInfo.getUserId();
            
            for(Task modifyOwner : modifyTasks)
            {
                modifyOwner.ownerid = currentUserId;
            }
            update modifyTasks;
            
        }
        catch(Exception e)
        {
            Apexpages.addMessage( new ApexPages.Message (ApexPages.Severity.ERROR, 'Error Message'));
        }
        
        tasksOwnedByQueue = [select id, subject, status, whatid, whoid from task where ownerid = :u.id and status != 'Completed'];
        
        totalCount = tasksOwnedByQueue.size();
        System.debug('//////////////////after changing ownership :- total number of tasks in queue is ' + totalCount);
        
        Apexpages.addMessage( new ApexPages.Message (ApexPages.Severity.INFO, 'Task ownership changed successfully'));
    }       
}