0

So I have a custom object called Transactions, and have recently made a list view button that will redirect the user to a visualforce page that will show the selected record, and provide a few buttons to allow the user to select different report types to create. These reports I will be using visualforce pages as well, and have run into an issue when trying to use the same custom controller.

The first visualforce page is called LCD_Report_Selection and uses a custom controller LCD_Report_Selection_Controller. The basic page and controller I have made so far is as follows ***ignore the registry part, was a potential solution I found online that was not working **** :

<apex:page standardController="LCD_Transaction__c" extensions="LCD_Report_Selection_Controller" recordSetVar="transactions">

<apex:pageBlock >
    <apex:pageBlockTable value="{!selected}" var="trans">
        <apex:column value="{!trans.id}"/>
        <apex:column value="{!trans.Transaction_Name__c}"/>
        <apex:column value="{!trans.Issuer_Name__c}"/>
    </apex:pageBlockTable>

    <div align="center">


    <apex:form >
    <table>
        <tr>
            <td>
                <apex:commandButton value="Pipeline Report" /> 
            </td>
            <td>
                <apex:commandButton value="Broad Pipeline Report" action="{!Broad_Pipeline}" /> 
            </td>
        </tr>
        <tr>
            <td>
                <apex:commandButton value="Long Comps Output" /> 
            </td>
            <td>
                <apex:commandButton value="Long Comps Output by Tranche" />                                     
            </td>
        </tr>
    </table>
    </apex:form>
        </div>


</apex:pageBlock>

public class LCD_Report_Selection_Controller {

public List<LCD_Transaction__c> transactions {get;set;}

private Registry r;

public LCD_Report_Selection_Controller(ApexPages.StandardSetController controller){
    List<LCD_Transaction__c> transactions = New List<LCD_Transaction__c>();
    transactions = controller.getSelected();
    saveTransactions(transactions);

    r = Registry.instance();
    r.add(LCD_Report_Selection_Controller.class, this);

    system.debug('transactions --- ' + transactions);
    system.debug('std set controller');
}


public void saveTransactions(List<LCD_Transaction__c> trans){
    transactions = trans;
}

public PageReference Broad_Pipeline(){

    PageReference report = Page.LCD_Broad_Pipeline_Report;
    report.setRedirect(true);
    return report;

}

}

What I am trying to achieve is when I press the broad pipeline report button, I would like to take the selected records and process them in a table on a seperate visualforce page. The issue I am running into is that since both pages use the same controller, when the second page is rendered it creates a new controller and does not have the selected transactions. I am attempting to create a second controller extension and pass a list of transactions to it, but have not been successful. What would be the best way to go about passing the transactions to the second visual forcepage? see below

<apex:page standardController="LCD_Transaction__c" extensions="LCD_Report_Selection_Controller" recordSetVar="LCDtransactions" renderAs="pdf" >

<apex:pageBlock>
    <apex:pageBlockSection>
        <apex:pageBlockTable value="{!transactions}" var="trans">
            <apex:column value="{!trans.TransBreakDate__c}"/>
            <apex:column value="{!trans.Issuer_Name__c}" />
            <apex:column value="{!trans.TransSponsorName__c}" />
            <apex:column value="{!trans.Issuer_Industry__c}" />

        </apex:pageBlockTable>
    </apex:pageBlockSection>
</apex:pageBlock>

1 Answer 1

1

Changing setRedirect(true) to setRedirect(false) may solve your problem.

One technique is to pass a command-line parameter containing the Id values in a comma-separated format. The first page sets the parameter and the second page reads the parameter and queries the corresponding records.

On the write side:

String[] ids = new String[] {};
for (LCD_Transaction__c t : transactions) ids.add(t.Id);

PageReference report = Page.LCD_Broad_Pipeline_Report;
report.getParameters().put('ids', String.join(ids, ','));
report.setRedirect(true);
return report;

On the read side:

String[] ids;
String s = ApexPages.currentPage().getParameters().get('ids');
if (s != null) ids = s.split(',');
else ids = new String[] {};
2
  • what do you mean by the read side? if both pages use the same controller than wouldn't the write and read sides be the same? Commented Jan 22, 2019 at 18:59
  • @StormMartinous Yes the same class could be used. The data is added to the URL by one instance of the class and extracted from the URL by another instance of the class.
    – Keith C
    Commented Jan 22, 2019 at 20:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .