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
brijender singh rathore 16brijender singh rathore 16 

Can anybody help me with this simple wrapper class functionality

THIS CODE IS WRITTEN TO SEARCH CONTACTS BY LASTNAME THROUGH SEARCH BOX IN VF PAGE.WHEN CONTACT DISPLAY IT ALSO SHOW ALL THE RELATED DISPENSORY ITEMS.MOTIVE IS TO ADD CHECKBOX BESIDE EVERY DISPENSORY ITEM AND WHEN I SELECT SOME OF THEM AND CLICK ON SUMBIT BUTTON IT WILL PERFORM AN OPERATION.



User-added image



NOW when i select the checkbox and click on submit i get nothing(check by debug) So motive is when i select the checkbox and click on submit i will be able to get that Dispensory item so that i can perform some operation from that by submit function

here is the controller class

public class SearchController {
  public Boolean SelectedRecord {get;set;}  
  private apexpages.standardController controller {get; set; }
  private contact l;
  public List<contact> searchResults {get; set; }
  public string searchText {
    get{
      if (searchText==null) searchText = '';
        return searchText;
    }
    set;
  }
  public SearchController(ApexPages.StandardController controller) {
    this.controller = controller;
    this.l = (contact) controller.getRecord();
    this.SelectedRecord = false;
  }

  public PageReference search() {
    if(SearchResults == null) {
      SearchResults = new List<contact>();
  }
    else{
      SearchResults.Clear();
    }
    String qry = 'SELECT Id, LastName, FirstName,account.id,Accountid, (SELECT Name FROM Dispensary_Items__r) FROM contact WHERE LastName like \'%'+searchText+'%\' Order By LastName';
    SearchResults = Database.query(qry);
    return null;
  }

  public List<cContact> contactList {get; set;}

  public List<cContact> getContacts() {
    if(contactList == null) {
      contactList = new List<cContact>();
      for(Dispensary_Item__c c: [SELECT  Id, Name FROM Dispensary_Item__c WHERE Id =: SearchResults[0].id]) {
        contactList.add(new cContact(c));
      }
      system.debug('contactList' +contactList);
    }
      return contactList;
  }

  public PageReference processSelected() {
    List<Dispensary_Item__c> selectedContacts = new List<Dispensary_Item__c>();
      for(cContact cCon: getContacts()) {
        if(cCon.selected == true) {
          selectedContacts.add(cCon.con);
        }
      }
    System.debug('These are the selected items...'+selectedContacts.size());
    for(Dispensary_Item__c con: selectedContacts) {
      system.debug(con);
    }
    contactList=null;
    return null;
  }
  public class cContact {
    public Dispensary_Item__c con {get; set;}
    public Boolean selected {get; set;}
    public cContact(Dispensary_Item__c c) {
      con = c;
      selected = false;
    }
   }  
}

here is the vf page

<apex:page standardController="Contact" extensions="SearchController">
 <apex:form id="searchForm">
  <apex:PageBlock mode="edit">        
    <apex:pageblockSection id="searchBlockSection">
        <apex:pageBlockSectionItem id="searchBlockSectionItem">
            <apex:outputLabel >Enter Patient lastname</apex:outputLabel>
            <apex:panelGroup >
                <apex:inputtext id="searchTextBox" value="{!searchText}">
                    
                </apex:inputtext>
                <strong><apex:commandButton Id="btnSearch" action="{!search}" rerender="renderBlock" status="status" title="Search" value="Search"></apex:commandButton></strong>                    
            </apex:panelGroup>
        </apex:pageBlockSectionItem>
    </apex:pageblockSection>
    <apex:actionStatus id="status" startText="Searching... please wait..."/>        
    <apex:pageBlocksection id="renderBlock" >
    
      <apex:repeat value="{!SearchResults}" var="o"   rendered="{!NOT(ISNULL(SearchResults))}">
         <apex:pageBlock title="{!o.lastname}">
        <apex:pageBlockSection >
        <apex:outputField value="{!o.FirstName}"/>
        <apex:outputField value="{!o.Accountid}"/>
        <apex:outputField value="{!o.id}"/>
         </apex:pageBlockSection>
         </apex:PageBlock>

      
        <apex:pageBlockSection >
        <apex:pageBlockTable value="{!o.Dispensary_Items__r}" var="c">
            <apex:column value="{!c.Name}"/>
                 <apex:column headerValue="Select">
                     <apex:inputCheckbox value="{!SelectedRecord}" />   
         </apex:column>
          <apex:outputField value="{!o.FirstName}"/>
        </apex:pageBlockTable>
       <apex:commandButton action="{!processSelected}" value="Submit"/>

        </apex:pageBlockSection>
    </apex:repeat>
    
           </apex:pageBlocksection>
        </apex:PageBlock>
        </apex:form>
        </apex:page>