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
shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com 

Mass delete using checkboxes from apex datatable.

Hi,

 Can anyone please help me in implimenting a functionallity. I want to delete multiple records from apex page block table, using apex checkboxes.All checked checkboxes must get deleted on click of a single button "mass delete".The visualforce code of my page is given below, need  help in method.Thanks in advance...

<apex:page Controller="TeamMemberAssignmentController" >
 <apex:sectionHeader title="Edit Records"/>
  <apex:form >
    <apex:pageBlock mode="inlineEdit" id="block">
        <apex:pageMessages />
        <apex:pageBlockSection >
            <apex:outputLabel value="User" for="searchUser"/>
            <apex:inputField value="{!accTeamMem.UserId}" id="searchName" required="false"/>
            <apex:outputLabel value="Account" for="searchAccount"/>
            <apex:inputField value="{!accTeamMem.AccountId}" id="searchAccount" required="false"/>
            <apex:outputLabel value="Role" for="searchRole"/>
            <apex:inputField value="{!accTeamMem.TeamMemberRole}" id="searchRole" required="false"/>
            

            <apex:commandButton value="Search" action="{!search}" rerender="block" status="status"/>
            <apex:commandButton value="Save"  action="{!save}" id="saveButton" rerender="block" status="status1"/>
         <apex:commandButton action="{!update1}"  id="editButton" value="Edit And Save"   />
        <apex:commandButton action=""  id="DeleteButton" value="Delete"   />

                           
         </apex:pageBlockSection><br/>


        <apex:actionStatus id="status" startText="Searching... please wait..."/>
         <apex:actionStatus id="status1" startText="Saving your record... please wait..."/>
              
              

                     <apex:pageBlockSection title="Search Results" id="resultsBlock" columns="2">
        <apex:pageBlockTable value="{!searchResults}" var="AccountTeamMember" rendered="{!NOT(ISNULL(searchResults))}">
         
       

                 


          <apex:column >
      <!-- <apex:outputLink title="" value="/{!row.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;-->
       <a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteAccount('{!AccountTeamMember.Id}');" style="font-weight:bold">Del</a>
     </apex:column>

             <apex:column HeaderValue="Mass Delete">
                     <apex:inputCheckbox title="mass delete" value="{!AccountTeamMember.Id}" />
             </apex:column>

    
          <apex:column value="{!AccountTeamMember.User.Name}" headerValue="User" width="100"/>
          <apex:column value="{!AccountTeamMember.Account.Name}" headerValue="Account" width="100"/>
                      <apex:column headerValue="Role" width="200">
 

            <apex:outputField value="{!AccountTeamMember.TeamMemberRole}">
             <apex:inlineEditSupport showOnEdit="saveButton, cancelButton,editButton" 
                        event="ondblclick" 
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>

 



            </apex:outputfield>
            </apex:column>
        </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>




<apex:actionFunction action="{!DeleteAccount}" name="DeleteAccount" reRender="form" >
   <apex:param name="accountteammemberid" value="" assignTo="{!SelectedAccountTeamMemberId}"/>
</apex:actionFunction>

  </apex:form>
</apex:page>

 i have funtion to delete, all i need to do is pass pass values of id's in checkboxes to this set accTeamToDeleteSet.

 Set  accTeamToDeleteSet = new Set
 List accTeamMemberToDeleteList = new List
 for (AccountTeamMember accTeam : [SELECT Id,AccountID,UserId from AccountTeamMember where Id in: accTeamToDeleteSet ])
 {
                    accTeamMemberToDeleteList.add(accTeam);
                }
delete accTeamMemberToDeleteList;

 

 

Best Answer chosen by Admin (Salesforce Developers) 
pankaj.raijadepankaj.raijade

have a look at this

 

http://wiki.developerforce.com/index.php/Wrapper_Class

 

if you still have issues feel free to ask.

If your issue is solved mark reply as solution.

 

 

Regards,

Pankaj Raijade.

All Answers

pankaj.raijadepankaj.raijade

you can do it using a wrapper class.

 

Write a wrapper class in you controller.

This will contains a boolean and an instance of teammember.

Create a list of wrapper class use it on VF page.

 

On VF page map Map boolean against the checkbox.

 

On the button click in controller loop through list and check the boolean and create another list to delete.

 

Regards,

Pankaj Raijade.

shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com

Thanks for replying pankaj. I am a newbie in salesforce ,so dont know much about it.Can u please help me with the wrapper class?

pankaj.raijadepankaj.raijade

have a look at this

 

http://wiki.developerforce.com/index.php/Wrapper_Class

 

if you still have issues feel free to ask.

If your issue is solved mark reply as solution.

 

 

Regards,

Pankaj Raijade.

This was selected as the best answer
shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com

thanks a tonne Pankaj, you saved me from doing a hell lot of work!!!!

Gaurav RajGaurav Raj

Hi Shrey,

May you share the piece of code. I am building a similar app with Mass Delete Button in it and i am stuck, getting no idea to move further.