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
RahulRahul 

Hello friends, Iam trying to implemant similar change owner functionality like leads on account.Please find the code which i have implemented(almost complete I need logic) and help me solve

User-added image

I want to implement similar button on Account where I select the List view and based on which I select the select all check box or select a specific set of records to click on change owner and change the owner of records

I have implemented a similar functionality, the only problem is  I need to add a select all check box at the top and when i chick on chage owner button it should get the owner id's of selected records and update it to the new owner and it should get only those records which are displayed based on list views.eg This Week record list view or last week record list view etc;
Please find the image of what I have Implemented
User-added image
Controller :-
public with sharing class AccountController1 {

    public AccountController1(ApexPages.StandardController controller) {

    }
    
    public List<Account> acc{get;set;}
   public AccountController1(ApexPages.StandardSetController controller1) 
{
        controller1.setPageSize(10);
        acc = new List<Account>();
        acc =  [Select Id,Name,Ownerid,(Select Id,name From contacts) From Account];


}
    public PageReference save(){
     update acc;

     return null;

    
    }

public void changeowner(){



}
}
Page :-
<apex:page standardController="Account" extensions="AccountController1"  recordSetVar="accounts">
<apex:form >
<apex:pageBlock mode="inlineEdit">
<apex:commandButton action="{!save}" value="save"/>
<apex:commandButton action="{!changeowner}" value="Change owner"/>
<apex:pageBlockSection >
<apex:pageBlockTable value="{!acc}" var="a" border="1">
<apex:column >
<Apex:inputCheckbox />
</apex:column>
<apex:column value="{!a.name}" style="padding:20px"/>
<apex:column headerValue="Contact Names" >
        <apex:pageBlockTable value="{!a.contacts}" var="con"  >       
<apex:column value="{!con.Name}" rendered="{!if(con.name!='null',true,false)}" />

</apex:pageblocktable>
</apex:column>
<apex:column headerValue="Owner Name">
 <apex:inputField value="{!a.ownerid}" />

        </apex:column> 
</apex:pageblocktable> 

</apex:pageBlockSection>
</apex:pageBlock>

</apex:form>
  
</apex:page>
 
Adilson Arcoverde JrAdilson Arcoverde Jr
Hi sumit,

First part of the problem: I need to add a select all check box at the top 
You should include as the first column of your <apex:pageBlockTable> the following:
<apex:column >
     <apex:facet name="header"><apex:inputCheckbox styleClass="checkAll" /></apex:facet>
     <apex:inputcheckbox/>
</apex:column>


You'll need to use some javascript to check all checkboxes. There a lot of examples on internet.

Second part of the problem:  it should get only those records which are displayed based on list views.eg This Week record list view or last week record list view

You have to change the Account query in you controller. Please, check the code below:
 
acc =  [Select Id,Name,Ownerid,(Select Id,name From contacts) From Account whete Id in :controller1.getRecords()];

Please let me know if it helps somehow.
 

Regards.