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
SFDC16SFDC16 

How to delete mass record without using wrapper class in vf page.

Hello,

On vf page I wnat  to delete multiple record   on seletct checkbox  using delte button. I have implemented using wrapper class but I don't want use wraper class.

User-added image
----------------------Controller---------------------

public with sharing class SRC_ServiceCloudHomePage4 {

  public List<product2> productlist{
        get {
            if (productlist== null) {
                productlist=  [select id, IsActive, Name, ProductCode, Battery_Type__c, Product_Image__c, Purchase_Date__c, Warranty__c, Description from Product2 where Battery_Type__c != 'Radio Battery'
       ];
            }
            return productlist;
        }
        set;
    }
    
    
       public List<Case> caseList{
        get {
            if (caseList == null) {
                caseList=[select id, Owner.Name, CaseNumber, Description, Product_Code__c, Reason, Status, Origin, CreatedDate From Case  ];
            }
            return caseList;
        }
        set;
      }
      
      
      
       public List<Observance_Managment__C > omlist{
        get {
            if (omlist== null) {
                omlist=[select id, Name, Owner.Name, Status__C, Battery_Number__c, Within_Warranty__c, Observed_Problem__c, Description__c, Case__r.CaseNumber from Observance_Managment__c  ];
            }
            return omlist;
        }
        set;
      }
      
     public product2 prData {get;set;}
     
    public String paramprouctId{get;set;}
    public Boolean displayPopUp {get;set;}
        

    public PageReference showPopup() {

         prData =  [select id, IsActive, Name, ProductCode, Battery_Type__c, Product_Image__c, Purchase_Date__c, Warranty__c, Description from Product2 where id=:paramprouctId];
        displaypopup = true;

        return null;

    }
    
   
    public String productId{get;set;}
    public product2 prData1{get;set;}
    
    public void deleteRecord()
    {
        System.debug('before calling delete methode'+productId);

            System.debug('************************'+productId);    

    
//            String productId= System.currentPageReference().getParameters().get('row_id');

        prData1=new product2();
        System.debug('prId'+productId);    
        prData1=[select id, IsActive, Name, ProductCode, Battery_Type__c, Product_Image__c, Purchase_Date__c, Warranty__c, Description from Product2 where id=:productId];
        System.debug('prData'+prData1);
      delete prData1;
        
    
    }

     
     
    
   
      
}


 
PINKY REGHUPINKY REGHU
Hi,
    Refer this link:
https://www.cloudforce4u.com/2013/06/visualforce-page-component-for-mass.html
Hope this helps.
Ajay K DubediAjay K Dubedi
Hi SFDC,
Below code can fulfill your requirements. Hope this will work for you.

Visualforce Page:
<apex:page standardController="Account" extensions="AccountDeleteWrapperCLs">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accWrap}" var="acc">
                <apex:column headerValue="select">
                    <apex:inputCheckbox value="{!acc.checkbox}"/>
                </apex:column>
                <apex:column headerValue="id">
                    <apex:outputField value="{!acc.accObj.id}"/>
               </apex:column>
               <apex:column headerValue="Name">
                    <apex:outputField value="{!acc.accObj.name}"/>
                </apex:column>
                <apex:column headerValue="Industry">
                    <apex:outputField value="{!acc.accObj.Industry}"/>
                </apex:column>
            </apex:pageBlockTable>
            <apex:pageBlockButtons >
                <apex:commandButton value="delete" action="{! deletecheckedRecs}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller:
public class AccountDeleteWrapperCLs{
    public list<Account> Acclist{get;set;}

    public ID currentPageID;

    public list<DeleteExample> accWrap {get;set;}

    public AccountDeleteWrapperCLs(ApexPages.StandardController controller) {

        accWrap = new list<DeleteExample>();

//Querying the Student records

        Acclist = [select id,name,industry from account];

//Iterating through all the records of the student object

        for(integer i =0;i<Acclist.size();i++){

//Creating a new Object of InnerClass

            DeleteExample conObj = new DeleteExample(false,Acclist[i]);

            accWrap.add(conObj);

        }

    }

//Method to delete the selected records

    public pagereference  deletecheckedRecs (){

//Iterating through the list

        for(integer i=0;i<accWrap.size();i++){

//Fetching data of the selected records

            if(accWrap[i].checkbox == true){

//deleting student records based on lists index

                delete accWrap[i].accObj;
            }
        }

// create visualforce page with name  deleteWrapperExample

        pagereference ref = new pagereference('/apex/AccountDeleteWrapperPage');

        ref.setredirect(true);

        return ref;

    }

//Inner  Class

    public class DeleteExample{

        public boolean checkbox{get;set;}

        public account accObj{get;set;}

        public DeleteExample(boolean checkbox,account acc)

        {

            checkbox = checkbox;

            accObj   = acc;

        }

    }

}


Please mark this as best answer if this solves your problem.

Thank you
Ajay Dubedi