0

I have a Visualforce page with a page block table which contains multiple rows based on the search result from sosl query.Now I need to select multiple rows using checkbox and on button click need to pass the id's of selected rows to create pdf of those records. the pdf i am getting is blank. Please help. thanks in advance

Controller

    public class TEST_soslQueryPageBlock {

      public string searchText {get;set;}

    public list<list<sObject>> soslResults {
        get {
            if(searchText != null && searchText != '') {
                soslResults = [FIND :searchText IN ALL FIELDS RETURNING  lead(Id,name, email), Contact(Id,name, email), Account(Id,name, phone)];
            }
            return soslResults;
        }
        set;
    }

    public class searchResultRow{
        public string sObjectTypeName {get;set;}
        public sObject record {get;set;}
        public Boolean isSelected{get;set;}

        public searchResultRow(sObject pObject) {
            record = pObject;
            sObjectTypeName = pObject.getSObjectType().getDescribe().getLabel();
            isSelected=false;
        }
    }   

    public list<searchResultRow> searchResults {
        get {
            searchResults = new list<searchResultRow>();
            Boolean isSelected=false;
            if(soslResults != null) {

                for(list<sObject> objectList : soslResults) {
                    for(sObject obj : objectList) {
                        searchResults.add( new searchResultRow(obj));

                    }
                }
            }
            return searchResults;
        }
        set;
    }

    public PageReference  generate()
    {
        PageReference pg;
        pg = Page.PdfTest;
        return pg;
    }
}

Vf page for pdf

<apex:page controller="TEST_soslQueryPageBlock">
    <apex:repeat value="{!searchResults}" var="a">
        <apex:outputPanel rendered="{!a.isSelected}">
                 {!a.sObjectTypeName}
                 {!a.record['Name']},  
         </apex:outputPanel> 
    </apex:repeat>
</apex:page>

Vf for search query

            <apex:inputText id="searchParam" value="{!searchText}"/>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Results" rendered="{!searchResults.size > 0}">
        <apex:pageBlockTable value="{!searchResults}" var="row">
            <apex:column >
                <apex:facet name="header">
                <apex:inputCheckbox onclick="cvCheckAllOrNone(this,'inputId')"/>   
                </apex:facet>
                <apex:inputCheckbox value="{!row.isSelected}"/>
            </apex:column>
            <apex:column value="{!row.record['Name']}"  />
            <apex:column value="{!row.sObjectTypeName}" headerValue="Type" />       
        </apex:pageBlockTable>
    </apex:pageBlockSection>
</apex:pageBlock>
      <apex:commandButton value="Generate PDF" action="{!generate}"/> 
</apex:form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.