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
nansi kela 21nansi kela 21 

how to remove selected items from selectlist ?

Hi,
how to remove selected items from selectlist ?

Thanks,
Nansi
Best Answer chosen by nansi kela 21
JyothsnaJyothsna (Salesforce Developers) 
Hi,

Please refer the below sample code.

Visualforce Page:
 
<apex:page controller="BulkDeletecont" showHeader="false">
 <apex:form >
 <apex:pageBlock rendered="{!delupdate}">
 
 <apex:pageBlockButtons location="bottom">
 <apex:commandButton value="BulkDelete" action="{!deleterec}"/>
 <apex:commandButton value="BulkUpdate" action="{!UpdateRec}"/>
 </apex:pageBlockButtons>
 <apex:pageBlockTable value="{!course1}" var="ct">
 <apex:column >
 <apex:inputCheckbox value="{!ct.ck}" />
 </apex:column>
 <apex:column headerValue="Course name">
 <apex:outputField value="{!ct.wp.name}"/>
 </apex:column>
 <apex:column headerValue="Course fee">
 <apex:outputField value="{!ct.wp.course_fee__c}"/>
 </apex:column>
 <apex:column headerValue="Duration">
 <apex:outputField value="{!ct.wp.Duration__c}"/>
 </apex:column>
 </apex:pageBlockTable>
 
 <!-- update records-->
 </apex:pageBlock>
 <apex:pageBlock title="Bulk update records" rendered="{!updateblock}">  
 <apex:pageBlockButtons location="bottom">
   <apex:commandButton value="Updaterecs" action="{!UpdateRec1}"/>
 </apex:pageBlockButtons>
 <apex:pageBlockTable value="{!updt}" var="ct1">

 <apex:column headerValue="Course name">
 <apex:inputField value="{!ct1.name}"/>
 </apex:column>
 <apex:column headerValue="Course fee">
 <apex:inputField value="{!ct1.course_fee__c}"/>
 </apex:column>
 <apex:column headerValue="Duration">
 <apex:inputField value="{!ct1.Duration__c}"/>
 </apex:column>
 </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
</apex:page>

Controller:
 
public with sharing class BulkDeletecont {

    public boolean delupdate { get; set; }

   // public list<wrapper1> course11 { get; set; }

    public boolean updateblock { get; set; }
    
    public list<wrapper1> course1 { get; set; }
    
     public  list<course__c> updt{set; get;}
    
      // constructor
     public BulkDeletecont(){
    delupdate =true;
    updateblock=false;
     course1=new list<wrapper1>();
    list<course__c> course2=[select name,course_fee__c,Duration__c from course__c];
    for(integer index=0; index<course2.size(); index++)
    {
       course1.add(new wrapper1(course2[index]));
    }
    }//end constructor
   // bulkdelete  records

    public PageReference deleterec() {
     list<course__c> del=new list<course__c>();
         for(integer index=0; index<course1.size(); index++){
         if(course1[index].ck==true){
         del.add(course1[index].wp);
         }
         }
         delete del;
         course1=new list<wrapper1>();
         list<course__c> course2=[select name,course_fee__c,Duration__c from course__c];
    for(integer index=0; index<course2.size(); index++)
    {
       course1.add(new wrapper1(course2[index]));
    }
        return null;
    }
    //bulkupdate records
    public PageReference UpdateRec() {
  updateblock =true;
   updt=new list<course__c>();
         for(integer index=0; index<course1.size(); index++){
         if(course1[index].ck==true){
         updt.add(course1[index].wp);
         }
         }
         
        return null;
   }
    public PageReference UpdateRec1() {
        update updt;
        updateblock =false;
        delupdate=true;
        course1=new list<wrapper1>();
    list<course__c> course2=[select name,course_fee__c,Duration__c from course__c];
    for(integer index=0; index<course2.size(); index++)
    {
       course1.add(new wrapper1(course2[index]));
    }
        
        return null;
    }
    //wrapper class
        public class wrapper1{
        public course__c wp{get; set;}
        public boolean ck{get; set;}
          public wrapper1(course__c co){
          wp=co;
          ck=false;
          }
        }
     
 
  

}

User-added image

Hope this helps you!
Best Regards,
Jyothsna

All Answers

Atul GuptaAtul Gupta
Hi Nansi, as per this (https://developer.salesforce.com/forums/?id=906F00000009EJtIAM) question.
What exactly do you want to do in controller and the page?
JyothsnaJyothsna (Salesforce Developers) 
Hi,

Please refer the below sample code.

Visualforce Page:
 
<apex:page controller="BulkDeletecont" showHeader="false">
 <apex:form >
 <apex:pageBlock rendered="{!delupdate}">
 
 <apex:pageBlockButtons location="bottom">
 <apex:commandButton value="BulkDelete" action="{!deleterec}"/>
 <apex:commandButton value="BulkUpdate" action="{!UpdateRec}"/>
 </apex:pageBlockButtons>
 <apex:pageBlockTable value="{!course1}" var="ct">
 <apex:column >
 <apex:inputCheckbox value="{!ct.ck}" />
 </apex:column>
 <apex:column headerValue="Course name">
 <apex:outputField value="{!ct.wp.name}"/>
 </apex:column>
 <apex:column headerValue="Course fee">
 <apex:outputField value="{!ct.wp.course_fee__c}"/>
 </apex:column>
 <apex:column headerValue="Duration">
 <apex:outputField value="{!ct.wp.Duration__c}"/>
 </apex:column>
 </apex:pageBlockTable>
 
 <!-- update records-->
 </apex:pageBlock>
 <apex:pageBlock title="Bulk update records" rendered="{!updateblock}">  
 <apex:pageBlockButtons location="bottom">
   <apex:commandButton value="Updaterecs" action="{!UpdateRec1}"/>
 </apex:pageBlockButtons>
 <apex:pageBlockTable value="{!updt}" var="ct1">

 <apex:column headerValue="Course name">
 <apex:inputField value="{!ct1.name}"/>
 </apex:column>
 <apex:column headerValue="Course fee">
 <apex:inputField value="{!ct1.course_fee__c}"/>
 </apex:column>
 <apex:column headerValue="Duration">
 <apex:inputField value="{!ct1.Duration__c}"/>
 </apex:column>
 </apex:pageBlockTable>
 </apex:pageBlock>
 </apex:form>
</apex:page>

Controller:
 
public with sharing class BulkDeletecont {

    public boolean delupdate { get; set; }

   // public list<wrapper1> course11 { get; set; }

    public boolean updateblock { get; set; }
    
    public list<wrapper1> course1 { get; set; }
    
     public  list<course__c> updt{set; get;}
    
      // constructor
     public BulkDeletecont(){
    delupdate =true;
    updateblock=false;
     course1=new list<wrapper1>();
    list<course__c> course2=[select name,course_fee__c,Duration__c from course__c];
    for(integer index=0; index<course2.size(); index++)
    {
       course1.add(new wrapper1(course2[index]));
    }
    }//end constructor
   // bulkdelete  records

    public PageReference deleterec() {
     list<course__c> del=new list<course__c>();
         for(integer index=0; index<course1.size(); index++){
         if(course1[index].ck==true){
         del.add(course1[index].wp);
         }
         }
         delete del;
         course1=new list<wrapper1>();
         list<course__c> course2=[select name,course_fee__c,Duration__c from course__c];
    for(integer index=0; index<course2.size(); index++)
    {
       course1.add(new wrapper1(course2[index]));
    }
        return null;
    }
    //bulkupdate records
    public PageReference UpdateRec() {
  updateblock =true;
   updt=new list<course__c>();
         for(integer index=0; index<course1.size(); index++){
         if(course1[index].ck==true){
         updt.add(course1[index].wp);
         }
         }
         
        return null;
   }
    public PageReference UpdateRec1() {
        update updt;
        updateblock =false;
        delupdate=true;
        course1=new list<wrapper1>();
    list<course__c> course2=[select name,course_fee__c,Duration__c from course__c];
    for(integer index=0; index<course2.size(); index++)
    {
       course1.add(new wrapper1(course2[index]));
    }
        
        return null;
    }
    //wrapper class
        public class wrapper1{
        public course__c wp{get; set;}
        public boolean ck{get; set;}
          public wrapper1(course__c co){
          wp=co;
          ck=false;
          }
        }
     
 
  

}

User-added image

Hope this helps you!
Best Regards,
Jyothsna
This was selected as the best answer