I have scenario redirecting from one visualforce page to another visualforce page using apex code and have also set some parameters for second visualforce page. I tried to retrive the id using apexpages.currentpage().getparameters().get(‘id’), but it is erroring out as attempt to de-reference a null object.
Here is my first visual force page :
<apex:page standardController="Account" extensions="Opportunity_list_by_RecordType_ext" >
<apex:form>
<apex:pageBlock title="Orders" id="orders">
<apex:outputLink value="/apex/OpportunityListView?{!account.id}" target="_top">Click Here</apex:outputLink>
</apex:pageBlock>
</apex:form>
</apex:page>
apex:outputLink value="/apex/OpportunityListView?{!account.id}" target="_top">Click Here</apex:outputLink
second visual force page:
<apex:page standardController="Account" extensions="OppListView">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton action="{!gotoAcct}" value="Back to Accounts"/>
</apex:pageBlockButtons>
<apex:PageBlockSection title="Opportunity" id="scheduleProducts" columns="1">
<apex:pageBlocktable value="{!scheduleArray}" var="e">
<apex:column headerValue="Opportunity Name"><apex:outputLink value="{e.iOLI"/></apex:column>
<apex:column headerValue="Stage"><apex:outputText value="{!e.iStageName}" /></apex:column>
<apex:column headerValue="Amount"><apex:outputText value="{!e.iAmount}" /></apex:column>
<apex:column headerValue="Close Date"><apex:outputText value="{!e.iCloseDate}" /></apex:column>
<apex:column headerValue="Agency"><apex:outputText value="{!e.iAgency}" /></apex:column>
<apex:column headerValue="Opportunity Record Type"><apex:outputText value="{!e.iRecordType}" /></apex:column>
</apex:pageBlocktable>
</apex:PageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller for 2nd vf page:
public with sharing class OppListView {
private list<Opportunity> theMOpps = new list<Opportunity>();
public Account acct{get;set;}
List<aOLIPlus> scheduleArray;
public OppListView(ApexPages.StandardController ctrl){
acct.Id = System.currentPageReference().getParameters().get('id');
//this.acct = (Account)Ctrl.getRecord();
theMOpps = [Select Name, StageName, Amount, CloseDate, Agency__c, RecordTypeId, RecordType.Name From Opportunity Where AccountId = :acct.Id Order By CloseDate DESC ];
scheduleArray = new List<aOLIPLus>();
for(Opportunity thisMaster : theOrders)
scheduleArray.add(new aOLIPlus(thisMaster, thisMaster.StageName, thisMaster.Amount, thisMaster.CloseDate, thisMaster.Agency__c,thisMaster.RecordTypeId,thisMaster.RecordType.Name));
}
public List<aOLIPlus> getScheduleArray()
{
return scheduleArray;
}
public PageReference gotoAcct()
{
String str = 'google.com';//+ acct.id;
PageReference newPage = new PageReference(str);
newPage.setRedirect(false);
return newPage;
}
//Wrapper class
public class aOLIPlus
{
public Opportunity iOLI {get; set;}
public String iStageName {get; set;}
public Decimal iAmount {get;set;}
public Date iCloseDate{get;set;}
public String iAgency {get; set;}
public String iRecordType {get; set;}
public Boolean selected {get; set;}
public aOLIPlus(Opportunity aa, String aStageName, Decimal aAmount, Date aCloseDate,String aAgency,String aRecordTypeId,String aRecordType)
{
iOLI = aa;
iStageName = aStageName;
iAmount = aAmount;
iCloseDate = aCloseDate;
iAgency = aAgency;
iRecordType = aRecordType;
selected = false;
}
}
}