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
Bryan HuntBryan Hunt 

Two VF pages sharing one controller, data not available in second VF page.

Hello,

 

I am trying to code two VF pages that share one controller. The first page displays some data along with a selection table. The second page renders the output as a PDF page.

 

All works well except the display of the "selected items" table. After the user presses the "Generate RMA" button, I create a new list with all of the rows that were selected in the first page. Nothing displays for this table. All other data displays correctly.

 

I will upload the code for all three objects.

 

One observation: I have one field that I display on the second page that I don't display on the first (Claim__c.Claim_Company__c). Nothing would ever display on the second page for that field until I included it as a hidden input field on the first page. Then it worked perfectly. The table object that will not display is also a field that never appears on the first page. Could this be a similar issue?

 

An update:

I added these two lines in the ClaimRMAPDFTemplate:

{!selectedCDLIs[0].Claim_LI_Total_Claim_Quantity_Involved__c}
{!CDLIs[0].CDLI.Claim_LI_Total_Claim_Quantity_Involved__c}

 

The first returned no value, the second returned the quantity from the first row of the selection table.

 

This again seems to indicate that the selected-row-list (created in savePDF method, appears to be empty in the ClaimRMAPDFTemplate. I have system.debug statements that show that the list is definitely populated.

Why does the second page see no data in that list?

 

My whole purpose for the second list is to exclude the rows in the first list that were not selected. Is it possible to simply skip rows in the second VF page that are not selected? I was experimenting with the "rendered" attribute. I could make it work on the column component, but not on the datatable component.

 

Thanks.

 

Bryan Hunt

Best Answer chosen by Admin (Salesforce Developers) 
Bryan HuntBryan Hunt

Bob,

 

I figured out how to make it work.  I'm not sure *why* this logic works versus my old code... ?

 

I moved the logic to populate the second list into the getter for the list... and voila!!

 

Here is the updated controller logic:

 

public class ClaimGenRMAController
{
    private Claim__c claim;
    public string reason {get;set;}
    public string comments {get;set;}
    public list<CDLIWrapper> CDLIs {get; set;}
    public list<Claim_Detail_Line_Item__c> selectedCDLIs
    {
        get
        {
        //
        // Create new list of (only) selected CDLIs for output on PDF
        //

            for (CDLIWrapper myCDLI : CDLIs)
            {
                if (myCDLI.selected == true)
                    selectedCDLIs.add(myCDLI.CDLI);
            }
            return selectedCDLIs;
        }
        set;
    } 

    public ClaimGenRMAController(ApexPages.StandardController stdController) 
    {
        this.claim = (Claim__c)stdController.getRecord();
        this.reason = 'Wrong Size';
        this.comments = '';       
        selectedCDLIs = new list<Claim_Detail_Line_Item__c>();
        CDLIs = new list<CDLIWrapper>();
        list<Claim_Detail_Line_Item__c> claimCDLIs = 
            [SELECT Id, 
                    Name,
                    Claim_LI_Total_Claim_Quantity_Involved__c,
                    Claim_LI_Material_Item_Number__c,
                    Claim_LI_Product_Type__c, 
                    Claim_LI_Key_Code__c,
                    Claim_LI_Lot_Control_Number__c,
                    Claim_LI_Description__c,
                    Claim_LI_Invoice_Number__c, 
                    Claim_LI_Invoice_Date__c  
            FROM Claim_Detail_Line_Item__c 
            WHERE Claim_LI_Claim__c = : ApexPages.currentPage().getParameters().get('ID')];

        for (Claim_Detail_Line_Item__c CDLI : claimCDLIs)
            CDLIs.add(new CDLIWrapper(CDLI));
    }   
    
    public PageReference savePDF()
    {
        //PageReference np = new PageReference('/apex/ClaimRMAPDFTemplate');
        //np.setRedirect(false);
        //return np;
        
        PageReference pdf = Page.ClaimRMAPDFTemplate;
        
        attachment attach = new attachment();
        blob body;
        
        try
        {
            body = pdf.getcontent();
        }
        catch (visualforceexception e)
        {
            body = blob.valueof('some text');    // This is used to pass unit test criteria
        }
        
        attach.body = body;
        attach.name = 'RMA-' + datetime.now().format('yyyy-MM-dd-hh:mm:ss');
        attach.isprivate = false;
        attach.parentid = claim.id;
        insert attach;
        
        return new pagereference('/' + claim.id);       
    }
    
    class CDLIWrapper
    {
        public boolean selected {get; set;}
        public Claim_Detail_Line_Item__c CDLI {get; set;}
        public CDLIWrapper(Claim_Detail_Line_Item__c CDLI)
        {
            this.CDLI = CDLI;
            this.selected = false;
        }
    }
}

 Any thoughts on why having the code there works where it wouldn't when in the savePDF method?

 

Thanks.

 

Bryan Hunt

All Answers

Bryan HuntBryan Hunt

First VF page:

<apex:page standardcontroller="Claim__c" extensions="ClaimGenRMAController">
    <apex:form >
    <apex:inputHidden value="{!Claim__c.Claim_Company__c}"/>
         
        <apex:sectionheader title="Claims RMA Creation"/>
        
        <apex:pageBlock title="Claim Header Data">
            <apex:pageBlockSection columns="2" showHeader="false">
                <apex:pageBlockSectionItem >
                    <apex:outputlabel value="Distributor"/>
                    <apex:outputField value="{!Claim__c.Claim_DI_Name__c}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputlabel value="Requested By"/>
                    <apex:outputField value="{!Claim__c.Owner.Name}"/>
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    <apex:outputlabel value="Claim Number"/>
                    <apex:outputField value="{!Claim__c.Name}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputlabel value="Reason for return"/>
                    <apex:selectlist value="{!reason}" multiselect="false" size="1">
                        <apex:selectOption itemValue="Wrong Size" itemLabel="Wrong Size"/>
                        <apex:selectOption itemValue="Wrong Color" itemLabel="Wrong Color"/>
                        <apex:selectOption itemValue="Wrong Quantity" itemLabel="Wrong Quantity"/>
                        <apex:selectOption itemValue="Wrong Style" itemLabel="Wrong Style"/>
                        <apex:selectOption itemValue="Duplicate" itemLabel="Duplicate"/>
                        <apex:selectOption itemValue="Cancelled" itemLabel="Cancelled"/>
                        <apex:selectOption itemValue="Defective" itemLabel="Defective"/>
                        <apex:selectOption itemValue="Damaged" itemLabel="Damaged"/>
                        <apex:selectOption itemValue="Other" itemLabel="Other"/>
                    </apex:selectlist>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection columns="1" showHeader="false">
                <apex:pageBlockSectionItem >
                    <apex:outputlabel value="Comments"/>
                    <apex:inputtextarea value="{!comments}" rows="5" cols="100"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

        </apex:pageBlock>
            
        <apex:pageBlock title="Claim Detail Line Item Data">
            <apex:pageBlockSection columns="1" showHeader="true">
                <apex:outputtext style="color:red" value="Select the Claim Detail Line Items that should be included on the RMA form"/>
                <apex:pageblocktable value="{!CDLIs}" var="CDLI">
                    <apex:column headervalue="Selected">
                        <apex:inputcheckbox value="{!CDLI.selected}"/>
                    </apex:column>
                    <apex:column headervalue="RMA Quantity">
                        <apex:inputfield value="{!CDLI.CDLI.Claim_LI_Total_Claim_Quantity_Involved__c}"/>
                    </apex:column>
                    <apex:column headervalue="Material Item Number" value="{!CDLI.CDLI.Claim_LI_Material_Item_Number__c}"/>
                    <apex:column value="{!CDLI.CDLI.Claim_LI_Product_Type__c}"/>
                    <apex:column value="{!CDLI.CDLI.Claim_LI_Key_Code__c}"/>
                    <apex:column value="{!CDLI.CDLI.Claim_LI_Lot_Control_Number__c}"/>
                    <apex:column value="{!CDLI.CDLI.Claim_LI_Description__c}"/>
                </apex:pageblocktable>
            </apex:pageblocksection>            
        </apex:pageBlock>
        
        <apex:commandbutton value="Generate RMA" action="{!savePDF}"/>
        
    </apex:form>
</apex:page>

 

Second VF page:

<apex:page standardcontroller="Claim__c" extensions="ClaimGenRMAController" renderas="pdf">
    <!-- Stylesheets -->
    <apex:stylesheet value="{!$Resource.PDFDocumentStyle}" />
    
    <c:PDFHeaderFooter type="header" position="center"><h1>{!Claim__c.Claim_Company__c} Return Authorization Request</h1></c:PDFHeaderFooter>   

    <apex:pageBlock >
        <apex:pageBlockSection columns="1" showHeader="false">
            <apex:pageBlockSectionItem labelstyle="width:150px;font-weight:bold">
                <apex:outputlabel value="Distributor:" for="dist"/>
                <apex:outputField value="{!Claim__c.Claim_DI_Name__c}" id="dist"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem labelstyle="width:150px;font-weight:bold">
                <apex:outputlabel value="Requested By:" for="owner"/>
                <apex:outputField value="{!Claim__c.Owner.Name}" id="owner"/>
            </apex:pageBlockSectionItem>

            <br/>

            <apex:pageBlockSectionItem labelstyle="width:150px;font-weight:bold">
                <apex:outputlabel value="Claim Number:" for="cnbr"/>
                <apex:outputField value="{!Claim__c.Name}" id="cnbr"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem labelstyle="width:150px;font-weight:bold">
                <apex:outputlabel value="Reason for return:  " for="rsn"/>
                <apex:outputText value="{!reason}" id="rsn"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
        
        <br/>
        
        <apex:pageBlockSection columns="1" showHeader="false">
            <apex:pageBlockSectionItem labelstyle="width:150px;font-weight:bold">
                <apex:outputlabel value="Comments:"/>
                <apex:outputText value="{!comments}"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>

    </apex:pageBlock>
    <br/><br/>
    <apex:pageBlock title="Parts/Quantities for return">
        <apex:pageBlockSection columns="1" showHeader="true">
            <apex:datatable value="{!selectedCDLIs}" var="c" border="1" cellpadding="5px"  columnsWidth="100px, 100px, 120px, 120px">
                <apex:column headervalue="Quantity" value="{!c.Claim_LI_Total_Claim_Quantity_Involved__c}"/>
                <apex:column headervalue="Part Number" value="{!c.Claim_LI_Material_Item_Number__c}"/>
                <apex:column headervalue="Invoice Number" value="{!c.Claim_LI_Invoice_Number__c}"/>
                <apex:column headervalue="Invoice Date" value="{!c.Claim_LI_Invoice_Date__c}"/>
            </apex:datatable>
        </apex:pageblocksection>            
    </apex:pageBlock>        

    <!-- Last Page Footer -->
    <c:PDFHeaderFooter type="footer" position="left">
        
        <i>Office Use Only:</i>
        <br/><br/>
        <apex:pageBlock >
        <apex:pageBlockSection columns="1" showHeader="false">
            <apex:pageBlockSectionItem labelstyle="width:200px;font-weight:bold">
                <apex:outputlabel value="Return Code:"/>
                <apex:outputText value="_______________"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
        <br/>
        <apex:pageBlockSection columns="1" showHeader="false">
            <apex:pageBlockSectionItem labelstyle="width:200px;font-weight:bold">
                <apex:outputlabel value="Return Authorized By:"/>
                <apex:outputText value="_______________"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>

    </apex:pageBlock>
    
    </c:PDFHeaderFooter>

</apex:page>

 

Controller:

public class ClaimGenRMAController
{
    private Claim__c claim;
    public string reason {get;set;}
    public string comments {get;set;}
    public list<CDLIWrapper> CDLIs {get; set;}
    public list<Claim_Detail_Line_Item__c> selectedCDLIs {get;set;} 

    public ClaimGenRMAController(ApexPages.StandardController stdController) 
    {
        //system.debug('Now in the object constructor');
        this.claim = (Claim__c)stdController.getRecord();
        this.reason = 'Wrong Size';
        this.comments = '';        
        CDLIs = new list<CDLIWrapper>();
        list<Claim_Detail_Line_Item__c> claimCDLIs = 
            [SELECT Id, 
                    Name,
                    Claim_LI_Total_Claim_Quantity_Involved__c,
                    Claim_LI_Material_Item_Number__c,
                    Claim_LI_Product_Type__c, 
                    Claim_LI_Key_Code__c,
                    Claim_LI_Lot_Control_Number__c,
                    Claim_LI_Description__c,
                    Claim_LI_Invoice_Number__c, 
                    Claim_LI_Invoice_Date__c  
            FROM Claim_Detail_Line_Item__c 
            WHERE Claim_LI_Claim__c = : ApexPages.currentPage().getParameters().get('ID')];

        for (Claim_Detail_Line_Item__c CDLI : claimCDLIs)
            CDLIs.add(new CDLIWrapper(CDLI));
    }   
    
    //public ClaimGenRMAController() 
    //{
    //}
    
    public PageReference savePDF()
    {
        //
        // Create new list of (only) selected CDLIs for output on PDF
        //
        selectedCDLIs = new list<Claim_Detail_Line_Item__c>();
        for (CDLIWrapper myCDLI : CDLIs)
        {
            system.debug('selected value: ' + myCDLI.selected);
            system.debug('Qty: ' + myCDLI.CDLI.Claim_LI_Total_Claim_Quantity_Involved__c);
            if (myCDLI.selected == true)
                selectedCDLIs.add(myCDLI.CDLI);
        }
        
        system.debug('size: ' + selectedCDLIs.size());
        //system.debug('Reason: ' + reason);
        //system.debug('Comments: ' + comments);
        PageReference np = new PageReference('/apex/ClaimRMAPDFTemplate');
        np.setRedirect(false);
        return np;
        
        //PageReference pdf = Page.ClaimRMAPDFTemplate;
        
        //attachment attach = new attachment();
        //blob body;
        
        //try
        //{
        //    body = pdf.getcontent();
        //}
        //catch (visualforceexception e)
        //{
        //    body = blob.valueof('some text');    // This is used to pass unit test criteria
        //}
        
        //attach.body = body;
        //attach.name = 'RMA-' + datetime.now().format('yyyy-MM-dd-hh:mm:ss');
        //attach.isprivate = false;
        //attach.parentid = claim.id;
        //insert attach;
        
        //return new pagereference('/' + claim.id);       
    }
    
    public list<Claim_Detail_Line_Item__c> getselectedCDLIs()
    {
        system.debug('Final count: ' + selectedCDLIs.size());
        if (selectedCDLIs.size() > 0)
            return selectedCDLIs;
        else
            return null;
    }
    
    class CDLIWrapper
    {
        public boolean selected {get; set;}
        public Claim_Detail_Line_Item__c CDLI {get; set;}
        public CDLIWrapper(Claim_Detail_Line_Item__c CDLI)
        {
            this.CDLI = CDLI;
            this.selected = false;
        }
    }
}

 

bob_buzzardbob_buzzard

Interesting one.

 

The behaviour of the Claim__c.Claim_Company__c is expected - the record that the standard controller makes available is populated via a reflection type process on the page itself, so the record only has the fields that are required for the page when the controller constructor fires.  When you get to the second page, the controller is already constructed, so that doesn't have any effect on the record.

 

This makes it seem pretty likely that the controller is only being created once rather than twice, which is the issue I was expecting to see I must admit.  Just for the sake of clarity, I notice that you have quite a bit of commented out code that was attempting to retrieve the PDF version of the page - I'm assuming you are seeing this problem with those lines commented out?

 

The only thing that seems slightly odd is that you have declared a getter and setter for the selected list:

 

public list<Claim_Detail_Line_Item__c> selectedCDLIs {get;set;}

 

but then provided another getter furhter down that is checking the side of the list. 

 

 

 

 

Bryan HuntBryan Hunt

Bob,

 

If I  understand correctly, inclusion of fields on VF page 1 is how the standard controller determines which fields to return as part of its query (e.g. Claim__c.Claim_Company__c).  So if I want to use data from the Claim record on the second page, I have to make sure that it is referenced on the first page.

 

Yes, it was my hope to only have one instance of the controller so that I could share the data between both pages.  I believe that the "trick" to that is to use the setRedirect(false).  At least that is what I gathered from another post.  It seems to work quite well with the exception of the second list.

 

The commented out code is for what the final process actually will be: not displaying the PDF page, but rendering it as an attachment to the Claim record.  It actually works perfectly, with the same caveat: I can't get the second table to render.

 

The two getters are actually some detritus from trying just about anything and everything I could think of to get the second list table visible.  I believe that the standard getter will work just fine if I can figure this thing out.

 

The odd thing is that the original list is readily available, the second list is not.  Not through the datatable and not through a simple field display.  Yet, system.debugs show that the second list is definitely populated.  Baffled....

 

Thanks for your assistance.

 

Bryan Hunt

bob_buzzardbob_buzzard

My understanding is the same as yours for the first couple of points.   The fact that you need fields in page 1 to use in page 2 very strongly suggests that it is indeed the same instance of the controller.

 

With regard to pulling back the PDF programmatically, you won't be able to do that as getting the content of a page as PDF takes place in a separate transaction - I've been bitten by this before.

 

If you have the debug in regarding the object's constructor, do you see that just the once?

 

 

Bryan HuntBryan Hunt

Bob,

 

The system.debug inside the constructor does confirm (via debug logs) that it is only run once.  So, same instance of controller is used by both pages.

 

Not sure what you mean about the PDF as attachment issue?  It works perfectly.

 

Thanks.

 

Bryan Hunt

bob_buzzardbob_buzzard

I mean that the data you enter in the first page won't be available in the PDF, as that will be generated in a separate transaction.  The fixed information will be fine, but I wouldn't expect your selected information to be available.  That was why I asked about it in my first post.

Bryan HuntBryan Hunt

Bob,

 

I'm still confused...  I selected an entry from the drop-down, then entered comments.  Both appear on my PDF attachment.

 

Thanks.

 

Bryan

bob_buzzardbob_buzzard

Without saving the record?  That's not been my experience in the past.  I had to save the record then go to a new page where the controller retrieved the content as an attachment.

bob_buzzardbob_buzzard

Just to clarify - I'm talking about using the getContent method of a PageReference rather than redirecting to another page.  I tried to do this for a quote PDF, but I had to save the changes to the opportunity before the getContent could pick them up. 

Bryan HuntBryan Hunt

Yes, a little different that what I'm doing here.

 

Both of my methods (display new page or direct to attachment) are working well for what I need. 

 

Just gotta figure out this list access....

 

Thanks.

 

Bryan Hunt

Bryan HuntBryan Hunt

Bob,

 

I figured out how to make it work.  I'm not sure *why* this logic works versus my old code... ?

 

I moved the logic to populate the second list into the getter for the list... and voila!!

 

Here is the updated controller logic:

 

public class ClaimGenRMAController
{
    private Claim__c claim;
    public string reason {get;set;}
    public string comments {get;set;}
    public list<CDLIWrapper> CDLIs {get; set;}
    public list<Claim_Detail_Line_Item__c> selectedCDLIs
    {
        get
        {
        //
        // Create new list of (only) selected CDLIs for output on PDF
        //

            for (CDLIWrapper myCDLI : CDLIs)
            {
                if (myCDLI.selected == true)
                    selectedCDLIs.add(myCDLI.CDLI);
            }
            return selectedCDLIs;
        }
        set;
    } 

    public ClaimGenRMAController(ApexPages.StandardController stdController) 
    {
        this.claim = (Claim__c)stdController.getRecord();
        this.reason = 'Wrong Size';
        this.comments = '';       
        selectedCDLIs = new list<Claim_Detail_Line_Item__c>();
        CDLIs = new list<CDLIWrapper>();
        list<Claim_Detail_Line_Item__c> claimCDLIs = 
            [SELECT Id, 
                    Name,
                    Claim_LI_Total_Claim_Quantity_Involved__c,
                    Claim_LI_Material_Item_Number__c,
                    Claim_LI_Product_Type__c, 
                    Claim_LI_Key_Code__c,
                    Claim_LI_Lot_Control_Number__c,
                    Claim_LI_Description__c,
                    Claim_LI_Invoice_Number__c, 
                    Claim_LI_Invoice_Date__c  
            FROM Claim_Detail_Line_Item__c 
            WHERE Claim_LI_Claim__c = : ApexPages.currentPage().getParameters().get('ID')];

        for (Claim_Detail_Line_Item__c CDLI : claimCDLIs)
            CDLIs.add(new CDLIWrapper(CDLI));
    }   
    
    public PageReference savePDF()
    {
        //PageReference np = new PageReference('/apex/ClaimRMAPDFTemplate');
        //np.setRedirect(false);
        //return np;
        
        PageReference pdf = Page.ClaimRMAPDFTemplate;
        
        attachment attach = new attachment();
        blob body;
        
        try
        {
            body = pdf.getcontent();
        }
        catch (visualforceexception e)
        {
            body = blob.valueof('some text');    // This is used to pass unit test criteria
        }
        
        attach.body = body;
        attach.name = 'RMA-' + datetime.now().format('yyyy-MM-dd-hh:mm:ss');
        attach.isprivate = false;
        attach.parentid = claim.id;
        insert attach;
        
        return new pagereference('/' + claim.id);       
    }
    
    class CDLIWrapper
    {
        public boolean selected {get; set;}
        public Claim_Detail_Line_Item__c CDLI {get; set;}
        public CDLIWrapper(Claim_Detail_Line_Item__c CDLI)
        {
            this.CDLI = CDLI;
            this.selected = false;
        }
    }
}

 Any thoughts on why having the code there works where it wouldn't when in the savePDF method?

 

Thanks.

 

Bryan Hunt

This was selected as the best answer
bob_buzzardbob_buzzard

Glad to hear you got there.  I really can't think why it would be working one way and not the other.  It almost smacks of some viewstate race condition, where the setter is called with the original empty list after the action method has completed and set up the revised list.  That doesn't match the order of execution though, so I'm still baffled.

skyfall007skyfall007

Hi,

 

I have a similar requirement. How are you storing the selectedList ?

 

Because for me, in order to get the selectedList, I need to write a pageReference method and hence it is not a property having getter setters. Therefore, I am getting a blank selected list on next page.

 

Please advice me.

 

Thanks.

skyfall007skyfall007

I need how did you implemet, onclick or action method for your checkBox for selection.

skyfall007skyfall007

I am able to see the selectedList

public class ControllerClass {
	public String currentPageId{get;set;}
	public List<orderWrapper> orderListWrapper{get;set;}
	public Order__c orderObj{get;set;}
    public String parId{get;set;}
    public List<Order__c> selectedOrders{get;set;}
    public List<MultiOrderWrapperClass> multiOrderList{get;set;}
    
	public ControllerClass(){
	currentPageId = ApexPages.currentPage().getParameters().get('id');
	orderListWrapper = new List<orderWrapper>();
    selectedOrders = new List<Order__c>();
    multiOrderList = new List<MultiOrderWrapperClass>();
    } 
	
	public List<orderWrapper> getOrders(){
        for(Order__c o : [Select Name From Order where *somecondition*])
                orderListWrapper.add(new orderWrapper(o));
        return orderListWrapper;
	}
	public PageReference getSelected(){
        selectedOrders.clear();    
        for(OrderWrapper ordWrapper : orderListWrapper)
        if(ordWrapper.selected == true)
        selectedOrders.add(ordWrapper.ord);
        return null;
	}
	
public PageReference init(){
		multiOrderList = new List<MultiOrderWrapperClass>();
        Order__c orderObj = [Select Name from Order__c where id=: currentPageId];
        List<Id> selectedOrderIds = new List<Id>();
        for(Integer i=0; i<selectedOrders.size();i++ ){selectedOrderIds.add(selectedOrders[i].id);}
        for(Order obj : [Select Name from Order where id IN : selectedOrderIds]){
									
        		MultiOrderWrapperClass mOrderObj = new MultiOrderWrapperClass(obj);
            	multiOrderList.add(mOrderObj);
        }
    
        PageReference pdf = Page.SecondVFPage;
        pdf.getParameters().put('id',currentPageId);
		Datetime temp = Datetime.newInstance(datetime.now().year(), datetime.now().month(),datetime.now().day());
        Attachment attach = new Attachment();
        blob body;
       try
        {
            body = pdf.getcontent();
        }
        catch (visualforceexception e)
        {
            body = blob.valueof('some text');    // This is used to pass unit test criteria
        }
       attach.body = body;
        attach.name = 'Name'; 
        attach.isprivate = false;
        attach.parentid = currentPageId;
        insert attach;
        return new PageReference('/'+currentPageId);
        
    
	}
	public PageReference cancel(){
	return new PageReference('/'+currentPageId);

	}
	public class OrderWrapper{
		public Order__c ord{get; set;}
		public Boolean selected {get; set;}
		public orderWrapper(Order o){
            ord = o;
            selected = false;
		}
	}
	public class MultiOrderWrapperClass{
		public String name{get;set;}
		public MultiOrderWrapperClass(Order Obj){
		this.name = Obj.Name;
		}
	}
}



 



First VF Page
<apex:page controller="Creative_MultipleOrderLine" sidebar="false"> 
	<apex:form >
		<apex:pageBlock title="Parent : {!parId}">
 			<apex:pageBlockButtons >
    			<apex:commandButton value="Generate Order" action="{!init}"/>
    			<apex:commandButton value="Cancel" action="{!cancel}"/>
 			</apex:pageBlockButtons>
 			<apex:pageBlockSection title="Related Order List">
 			
 			 
 				<apex:dataTable value="{!orders}" var="o" columnswidth="50px,50px" cellpadding="4" border="1">
 				<apex:column >
 				<apex:facet name="header">
 				<!--<apex:inputCheckbox onclick="{!selectedOrders}">
 					  <apex:actionSupport event="onclick" action="{!getSelected}" onsubmit="checkAll(this)" rerender="Selected_ORD"/>
				</apex:inputCheckbox>-->
				</apex:facet>
			 	<apex:inputCheckbox value="{!o.selected}" id="checkedone">
					  <apex:actionSupport event="onclick" action="{!getSelected}" rerender="Selected_ORD"/>
				</apex:inputCheckbox>
				</apex:column>
				<apex:column headervalue="Order ID" value="{!o.ord.Name}" />
				</apex:dataTable>
			</apex:pageBlockSection>
			<apex:pageBlockSection Title="Selected Order List" id="Selected_ORD">
			<apex:dataTable value="{!SelectedOrders}" var="s" columnswidth="50px,50px" cellpadding="4" border="1">
			<apex:column headervalue="Order ID" value="{!s.Name}" />
			</apex:dataTable> 
			</apex:pageBlockSection>
			
		</apex:pageBlock>
	</apex:form>
</apex:page>

SecondVF Page
<apex:page controller="Creative_MultipleOrderLine" showheader="false" renderas="pdf"> 
View {!multiOrderList} View
</apex:page

 I am getting empty list on my second VF PDF page attachement.

employAstar 5employAstar 5
Thanksa for the information.I have a simillar situation where i have a single controoler and have two Vf pages where in there is invoice feild Auto number which is standard name feild type auto number.on clickinggenrating invoice button i get a PDF page which is returned and in this i can see the auto number feild in VF page and when the same page is attached as PDF Auto Number feild goes missing.
Currently we are taking the old values from contructor and incrementing by 1 and displaying which works all fine but in case if simultaneouly there are two invoices generated the problem arises.
Please any could help as i have been trying to sort it out more than a month now but all the options i tried didnt give me the desired result
employAstar 5employAstar 5
VF Page 1 from generating Invoice
<apex:page standardController="Invoice__c" extensions="GSTorginal" showHeader="false"  applyHtmlTag="false" renderAs="pdf" applyBodyTag="false">
<tr><apex:panelGroup rendered="{!taxa!='GST'}"><td height="50%" colspan="4"><h>To</h><br/><br/>
{!acc.BillingStreet}<br/>{!acc.BillingCity}<br/>{!acc.BillingState}&nbsp;{!acc.BillingPostalCode}<br/>{!acc.BillingCountry}&nbsp;{!acc.BillingLatitude}&nbsp;{!acc.BillingLongitude}                   
</td>
</apex:panelGroup>

</apex:panelGroup><td height="50%" colspan="5">
<apex:panelGroup rendered="{!acc.Name !='PricewaterHouse Coopers Pvt Ltd'}">
<h align="right" style="display:{!if(flag=='attach','','none')}">
Invoice&nbsp;No&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp; 1--{!inm1.name}<br/></h>
<h align="right" style="display:{!if(flag=='false','','none')}">
Invoice&nbsp;No&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;2---{!inm1.name }<br/></h>
<h align="right" style="display:{!if(flag=='print','','none')}">
Invoice&nbsp;No&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;3-- {!inm1 } <br/></h>
<h align="right" style="display:{!if(flag=='view','','none')}">
Invoice&nbsp;No&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;IE-00{!invNo+1} <br/></h>    
</apex:panelGroup>
<apex:panelGroup rendered="{!acc.Name =='PricewaterHouse Coopers Pvt Ltd'}"> 
<h align="right" style="display:{!if(flag=='attach','','none')}">
Invoice&nbsp;No&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp; {!inm1}-<apex:outputText value="{0, date,yyyy}">
<apex:param value="{!TODAY()}" /></apex:outputText> <br/></h>
<h align="right" style="display:{!if(flag=='false','','none')}">
Invoice&nbsp;No&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;IE-00{!invNo }-<apex:outputText value="{0, date,yyyy}">
<apex:param value="{!TODAY()}" /></apex:outputText> <br/></h>
<h align="right" style="display:{!if(flag=='print','','none')}">
Invoice&nbsp;No&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp; {!inm1 }-<apex:outputText value="{0, date,yyyy}">
<apex:param value="{!TODAY()}" /></apex:outputText> <br/></h>
<h align="right" style="display:{!if(flag=='view','','none')}">
Invoice&nbsp;No&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;IE-00{!invNo+1}-<apex:outputText value="{0, date,yyyy}">
<apex:param value="{!TODAY()}" /></apex:outputText> <br/></h> 
</apex:panelGroup>
</td>
</tr>
</table>
</td>
</tr>
</table> 
 </div>
    </body>
  </html>

</apex:page>
employAstar 5employAstar 5
public GSTorginal(ApexPages.StandardController sc){       
appointment1 = new SCSCHAMPS__Appointment__c();
appde= new SCSCHAMPS__Appointment__c();
invBill=new Invoice__c();
cb=false;
invfp = new Invoice__c();
totall = 0;
contactList  = new List<ContactWrapper>();
         AppList = new List<AppWrap>();

 addMore();
 selectedRowIndex = '0';

 flag='false';
 system.debug('**appointment1.SCSCHAMPS__Employer__c**'+appointment1.SCSCHAMPS__Employer__c);
 system.debug('---Initial Flag'+flag);
 inv = [select id,name,invoicetext__c from invoice__C order by name desc limit 1];
    
  String s1= inv.Name;
  invNo = (Long)Long.valueOf( s1.substring(3));

employAstar 5employAstar 5
public PageReference returnPage(){
Pagereference ref;
//
Some code to generate invoice
//  
attachPdfToAccount( invBill.Billing_Calendar__c, appointment.SCSCHAMPS__Employer__c,inv.id); 
   
       flag = 'attach';   
  
            return ref;
}
public void attachPdfToAccount(String  invBillCalendar, String appointmentEmployer, String invId){  
  try{        
if(ep=='None'&& desp!=null)
{
 this.ep=desp;
 }
            else{
               this.ep=ep;
              } 
              Billing_Calendar__c bc=new Billing_Calendar__c();
              bc=[select id,Name, Invoicing_Start_Date__c,Invoicing_End_Date__c from Billing_Calendar__c where Billing_Calendar__c.id=:invBillCalendar limit 1];
                Account acc = [select id,Name from Account where ID=:appointmentEmployer]; 
                Attachment myAttach1 = new Attachment();
                flag = 'attach';
                myAttach1.ParentId = invId;
                inm1= [SELECT id,Name,Invoice_Date__c,invoicetext__C  FROM Invoice__c Where Id =: invId];
      inm1.invoicetext__C=inm1.name;
      update inm1;
                myAttach1.name =inm1.invoicetext__C+'.pdf';
                pagereference ref=page.FAGSTVFPORGINAL;
                ref.getParameters().put('inm1',String.ValueOf(inm1.invoicetext__C));
               ref.getParameters().put('inm1',String.ValueOf(inm1.Name));
                 ref.getParameters().put('inm1',inm11);
                  ref.getParameters().put('inm1',inm12);
                ref.getParameters().put('id',invid);
                ref.getParameters().put('accId',acc.Id);
                ref.getParameters().put('flag1',String.valueOf(flag));
                ref.getParameters().put('ep1',ep);
                ref.getParameters().put('toi1',toi);
                ref.getParameters().put('stax1',stax);
                ref.getParameters().put('scurr1',scurr);
                ref.getParameters().put('pos',pos);
                ref.getParameters().put('sop1',sop);
                ref.getParameters().put('ids',strids);                
                //GST Implementation
                ref.getParameters().put('taxa1',taxa);
                ref.getParameters().put('addG1',addG);
                ref.getParameters().put('gst1',gst);
             
                ref.getParameters().put('startDate',string.valueOf(bc.Invoicing_Start_Date__c));
                ref.getParameters().put('endDate',string.valueOf(bc.Invoicing_End_Date__c));
                  ref.getParameters().put('invt',invoicetext);
                
                if(edate!=null)
                ref.getParameters().put('edt',string.valueOf(edate));
                else 
                ref.getParameters().put('edt',string.valueOf(Date.Today())); 
                if(bdate!=null)
             ref.getParameters().put('bdt',string.valueOf(bdate));
            else 
             ref.getParameters().put('bdt',string.valueOf(Date.Today())); 
               ref.setRedirect(false);
                //myAttach1.body = ref.getContentAsPDF();    
               
               ref.getParameters().put('flag1','print');
               Blob body;
               
                try {

          // returns the output of the page as a PDF
             body = ref.getContent();
             

            // need to pass unit test -- current bug    
             } catch (VisualforceException e) {
            body = Blob.valueOf('Some Text');
         }
          myAttach1.body=body;
          myAttach1.IsPrivate = false;
         insert myAttach1;
      list<attachment> alist=[select id,name from attachment where id=:inm1.id];
        inm5=[SELECT Id, Name, invoicetext__c,(SELECT Id, Name FROM Attachments) FROM invoice__c order by name desc limit 1];
ref.getParameters().put('inm5',string.valueOf(inm5)); 
         
            }
            catch(Exception e) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There was an error while attaching'));
                System.debug('Exception');
            }

}