+ Start a Discussion
brijender singh rathore 16brijender singh rathore 16 

can anybody help me to complete this task

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



so far my code


public class SearchController {
  public Boolean SelectedRecord {get;set;}  
  private apexpages.standardController controller {get; set; }
  private contact l;
  public set<id> conid;
  public List<contact> searchResults {get; set;}
  public List<Dispensary_Item__c> Results {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);
    conid = (new Map<Id,contact>(SearchResults)).keySet();
    system.debug('contactList' +conid);

    return null;
  }

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

  public List<cContact> getContacts() {
        system.debug('contactList' +conid);
 
    if(contactList == null) {
      contactList = new List<cContact>();

      for(Dispensary_Item__c c: [SELECT  Id, Name FROM Dispensary_Item__c WHERE patient__c in : conid ]) {
        contactList.add(new cContact(c,SelectedRecord));
      }
      system.debug('contactList' +contactList);
    }
      return contactList;
  }

  public PageReference processSelected() {
            system.debug('contactList' +conid);

    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;
    }
   }  
}
                                                                                      VF
_______________________________________________________________________________________________________



<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>