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
Rocio VivancoRocio Vivanco 

Error by passing parameters from one Visualforce page to another

Hi all,

I am trying to pass a parameter from one Visualforce to another.

I need to display / filter opportunities to an Account I gave in the first visualforce.

Here is the part where I declare the "passing" of the AccountId to the second visualforce:
 
public PageReference GoTo_VRWithOptys (){
        string value = 'accountId';
        string url;
        url = '/apex/Visit_Report_with_Opportunities?param1=' + accountId; 

        PageReference pageRef = new PageReference(url);
        pageRef.setRedirect(true);
        return pageRef;
        
    }

In my second Visualforce "Visit_Report_with_Opportunities" I am referencing that parameter in order to show only the opportunities to that account:
 
<apex:pageBlock id="pagination" title="Opportunity Details">
         <apex:pageBlockTable value="{!param1}" var="o" >
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.CloseDate}"/>
             <apex:column value="{!o.Amount}"/>
            <apex:column value="{!o.CloseDate}"/>
         </apex:pageBlockTable>
The apex to the second Visualforce page looks like this:
 
public String optyquery;
	public String name {get;set;}
	public Date closedate {get;set;} 
    public Boolean fetchCalled {get;set;} 
    public integer totalRecs {get;set;}
    private integer index = 0;
    private integer blockSize = 5; 
    Id param1 {get;set;}
    String param_value {get;set;}
    
  
    public PaginationWithFilter()
    {
        param_value = System.CurrentPageReference().GetParameters().get('param1');
        totalRecs = [select count() from Opportunity where Days_since_created__c <=365 and Account.Id =: param1];       
        fetchCalled = false;
        
    } 
  
    public void fetch()
    {         
       
        optyquery = 'SELECT Name, CloseDate FROM Opportunity where Days_since_created__c <=365 and Account.Id =: param1 ';
        
        List<Opportunity> tempopty = Database.Query(optyquery);
        totalRecs = tempopty.size();  
       
        optyquery += ' LIMIT ' + blockSize + ' OFFSET ' + index; 
       
        fetchCalled = true;                        
    }       
   
    public List<Opportunity> getOpty()
    {      
        List<Opportunity> optys;
        if(fetchCalled)
        {
            fetch();
        }  
        else
        {
            optyquery = 'SELECT Name, CloseDate FROM Opportunity where Days_since_created__c <=365 and Account.Id =: param1 LIMIT : blockSize OFFSET : index';
        }          
        optys = Database.Query(optyquery);       
        System.debug('Values are ' + optys);
        return optys;       
    }
When I try to save the second visualforce, the error I get is:
 
Error: Unknown property 'param1' referenced in Visit_Report_with_Opportunities
I also tried replacing "param1" by "accountId" but the error then says:
Error: Unknown property 'accountId' referenced in Visit_Report_with_Opportunities

Is there here something missing?



 
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hi,
Why are you using custom pagination? You can use standard salesforce pagination. Your code is not optimized and need to refacrtored it as some of the variables not required. Anyway, you can try this - 
public String optyquery;
	public String name {get;set;}
	public Date closedate {get;set;} 
    public Boolean fetchCalled {get;set;} 
    public integer totalRecs {get;set;}
    private integer index = 0;
    private integer blockSize = 5; 
    public List<Opportunity>  oppList {get;set;}
    String param_value {get;set;}
    
  
    public PaginationWithFilter()
    {
        param_value = System.CurrentPageReference().GetParameters().get('param1');
        totalRecs = [select count() from Opportunity where Days_since_created__c <=365 and Account.Id =: param1];       
        fetchCalled = false;
        
    } 
  
    public void fetch()
    {         
       
        optyquery = 'SELECT Name, CloseDate FROM Opportunity where Days_since_created__c <=365 and Account.Id =: param1 ';
        optyquery += ' LIMIT ' + blockSize + ' OFFSET ' + index;
        oppList = Database.Query(optyquery);
        totalRecs = tempopty.size();         
        fetchCalled = true;                        
    }       
   
    public List<Opportunity> getOpty()
    {      
        if(fetchCalled)
		{
            fetch();
        }  
        else
        {
            return Database.Query('SELECT Name, CloseDate FROM Opportunity where Days_since_created__c <=365 and Account.Id =: param1 LIMIT : blockSize OFFSET : index');       
        }              
        System.debug('Values are ' + optys);
        return null;       
    }
 
<apex:pageBlock id="pagination" title="Opportunity Details">
         <apex:pageBlockTable value="{!oppList}" var="o" >
            <apex:column value="{!o.Name}"/>
            <apex:column value="{!o.CloseDate}"/>
             <apex:column value="{!o.Amount}"/>
            <apex:column value="{!o.CloseDate}"/>
         </apex:pageBlockTable>

Thanks, 
Sumit Kumar Singh
Rocio VivancoRocio Vivanco
Thanks Summit for your answer. So, for the pagination I don't need any code?.
Shiva RajendranShiva Rajendran
Hi Rocio ,
I have looked into your code. It looks fine.
param1 is the correct way to access.
I hope you directly opened the page2 or may be you haven't passed parameter properly from the vf page 1.

Try this 
use this url at the top of the browser.. if the code works ,thinks are fine ..problem is in passing variable from vf1 controller.
salesforceURLinstance/apex/Visit_Report_with_Opportunities?param1= (replace with opportunity id that exists in your org)
public String optyquery;
	public String name {get;set;}
	public Date closedate {get;set;} 
    public Boolean fetchCalled {get;set;} 
    public integer totalRecs {get;set;}
    private integer index = 0;
    private integer blockSize = 5; 
    Id param1 {get;set;}
    String param_value {get;set;}
    
  
    public PaginationWithFilter()
    {
	if(ApexPages.currentPage().getParameters().containsKey('param1') && ApexPages.currentPage().getParameters().get('param1') != '')
         {
		   param_value = System.CurrentPageReference().GetParameters().get('param1');
        totalRecs = [select count() from Opportunity where Days_since_created__c <=365 and Account.Id =: param1];       
        fetchCalled = false;
                    System.debug('param1 exists' + param_value);
          }
		  else{
		  
		                      System.debug(' no param1 exists' );

		  }
      
        
    } 
  
    public void fetch()
    {         
       
        optyquery = 'SELECT Name, CloseDate FROM Opportunity where Days_since_created__c <=365 and Account.Id =: param1 ';
        
        List<Opportunity> tempopty = Database.Query(optyquery);
        totalRecs = tempopty.size();  
       
        optyquery += ' LIMIT ' + blockSize + ' OFFSET ' + index; 
       
        fetchCalled = true;                        
    }       
   
    public List<Opportunity> getOpty()
    {      
        List<Opportunity> optys;
        if(fetchCalled)
        {
            fetch();
        }  
        else
        {
            optyquery = 'SELECT Name, CloseDate FROM Opportunity where Days_since_created__c <=365 and Account.Id =: param1 LIMIT : blockSize OFFSET : index';
        }          
        optys = Database.Query(optyquery);       
        System.debug('Values are ' + optys);
        return optys;       
    }
Let me know if you need further help.

Thanks and Regards,
Shiva RV.