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
SARTHAK GARG 4SARTHAK GARG 4 

How to apply search interface to the list of wrapper class?What should we write in search function....

User-added imagewant to search   below the name from below list dynamicalyy;

Here is the controller

 

 

public with sharing class Sim_EventOfficeContactsController {
    
    public List<OfficeContactWrapper> officeContacts {get;set;}
    private List<Office_Contact__c> toBeDeleted{get;set;}
    public Integer selectedIndex{get;set;}
    private Integer index{get;set;}
    
    private String eventId;
    public id eventAccountid;
    
    public String searchstr{get;set;}
    
    public Sim_EventOfficeContactsController(ApexPages.StandardController controller) {
        toBeDeleted = new List<Office_Contact__c>();
        eventId = controller.getId();
        List<Event_and_Lecture__c> eventList = [select id,account__r.Id from Event_and_Lecture__c where id = :eventId limit 1];
        eventAccountid = eventList[0].account__r.Id;
        system.debug('eventAccountid: '+eventAccountid);
        initOfficeContacts();    
    }
    
    
    public pagereference dosearch(){
        String strg = '%'+searchstr+'%';
        =[SELECT id,name FROM Office_Contact__c WHERE name like:strg];
       return null;
    }    
    
    
    
    public boolean getHasContacts(){
        return officeContacts.size()>0;
    }
    
    //methods for getting list of contacts
    public void initOfficeContacts()
    {   
        officeContacts = new List<OfficeContactWrapper>();
        index = 1;
        //if viewing on standard controller (account), add in filter for accountId
        for(Office_Contact__c officeContact : [SELECT id, name,Event_and_Lecture__c,email__c,CORE_Referral_Manager__c ,Phone__c, account__c, Type__c, Preferences__c
                                               FROM Office_Contact__c WHERE account__c = :eventAccountid ORDER BY Name asc LIMIT 1000]){
              OfficeContactWrapper ocw = new OfficeContactWrapper(officeContact,index);
            officeContacts.add(ocw);
            index++;                
        }
        
    }
    
    //save all records that were updated
    public void save() 
    {
        List<Office_Contact__c> toUpsert = new List<Office_Contact__c>();
        for(OfficeContactWrapper ocw: officeContacts){
            toUpsert.add(ocw.officeContact);
        }
        upsert toUpsert;
        delete toBeDeleted;
        initOfficeContacts();
    }
    
    public void add()
    {
        Office_Contact__c ref = new Office_Contact__c(Event_and_Lecture__c = eventId, account__c = eventAccountid);
        officeContacts.add(new OfficeContactWrapper(ref,index));
        index++;
    }
    
    public void delRow()
    {   
        integer index = 0;
        System.debug('rowIndex for delete'+ selectedIndex);
        for(OfficeContactWrapper ocw: officeContacts){
            if(ocw.rowIndex == selectedIndex){
                if(ocw.officeContact.Id != null)
                    toBeDeleted.add(ocw.officeContact);
                break;
            }
            index++;
        }
        officeContacts.remove(index);
        save(); 
    }
    class OfficeContactWrapper{
        public Office_Contact__c officeContact{get;set;}
        public Integer rowIndex{get;set;}
        public OfficeContactWrapper(Office_Contact__c officeContact,Integer rowIndex){
            
            this.officeContact = officeContact;
            this.rowIndex = rowIndex;
        }
    }
}