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
rosscorossco 

Cannot access parameter passed in the URL

Hi

 

I am having difficulty in accessing a parameter passed in a URL from one viuslforce page to another. I have two pages (atrainingconfirmatation and  atrainingfconfirmation2). They both use the same controller. The first one prompts the user to select a company who has delegates on this event. The second print a confirmation form. The first page passes the selected accountid to the second. In the controller, I use the accountid to select all the delegates for the event for the passed accountid but am getting no data. This is the code where the passed parameter is used

 

   public List<CQS_Delegate__c> getdelegates(){
        delegate = [SELECT Contact__c,No_of_Delegates__c,Contact__r.Name,Dietary_Requirement__c,Account__r.Name,Payment_Status__c from CQS_Delegate__c WHERE Event__c =:eventid and Account__c=:accountpassedid];
             return delegate;
    }

 

Page1:

 

<apex:page Controller="TrainingConfirmation" sidebar="false"  showheader="false">
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title="Training Confirmation - Select Company" columns="1">
      <apex:pageblocksectionItem >
                  <apex:selectList value="{!accountId}" size="1" id="accountId">
              <apex:selectOptions value="{!accounts}"/>
          </apex:selectList>
      </apex:pageblocksectionItem>    
                            </apex:pageblocksection>           
  </apex:pageblock>

<apex:commandlink value="Click here to Generate Training Confirmation" action="{!genConfirm}"/>
</apex:form>
</apex:page>


 

Page2:

<apex:page Controller="TrainingConfirmation" renderas="PDF" sidebar="false"  showheader="false">

<html>
<head>
<style>
    body{
        font-family:Verdana, Geneva, sans-serif;
        font-size:12px;
    }
    .H1{
        color:#A3CC03;
        font-size:36px;
    }
    .H2{
        font-size:18px;
    }
    .table-heading1{
        color:#374B60;
        background-color:#CCC;
        font-weight:bold;
        padding:2px;
        font-size:14px;
    }
    .table-heading2{
        color:#374B60;
        background-color:#FFF;
        font-weight:bold;
    }
    .table-text{
        color:#374B60;
        background-color:#FFF;
        font-size:10px;
    }
    
    .table-bottom-line{
        border-top:solid 1px #374B60;
    }
    
    .statutory{
        font-size:10px;
    }
</style>

</head>
    <table width="720px" align="center" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td style="text-align:center">&nbsp;</td>
        </tr>
        <tr>
            <td style="text-align:center">
                <apex:image value="{!$Resource.CQSLogo}" />
            </td>
        </tr>
        <tr>
            <td style="text-align:center">&nbsp;</td>
        </tr>
        <tr>
            <td style="text-align:center" class="H1">Training Confirmation</td>
        </tr>
        <tr>
            <td style="text-align:center">&nbsp;</td>
        </tr>
        <tr>
            <td style="text-align:center">&nbsp;</td>
        </tr>
        <tr>
            <td style="text-align:center" class="H2">Course: {!event.name}</td>
        </tr>
        <tr>
          <td style="text-align:center">Course Date: <apex:outputText value="{0,date, dd MMM yyyy}">
                                <apex:param value="{!event.Start_Date__c}"/>
                            </apex:outputText> 
                            </td>
</tr>
        <tr>
                                <td style="text-align:center">&nbsp;</td>
        </tr>
        <p></p>
        <br></br>
        <br></br>
           Date: <apex:outputText value="{0,date, dd MMM yyyy} "> 

        <apex:param value="{!NOW()}"/>
                            </apex:outputText> 
<br></br>
<br></br>
Thank you for booking the following Delegates on the above CaseWare Training Course<br></br>          
Payment for all training has to be made in advance. You will find our bank details on the attached invoice.<br></br>             
Please fax proof of payment to (011) 252 9424.          <br></br>
    <p></p>
<h3>Cancellation Policy:</h3>                
As our training courses are extremely popular, please note that bookings have to be cancelled in writing at least 5 working days                
prior to the scheduled training date. At NO time are telephonic cancellations acceptable.      <br></br>         
Late cancellations will be changed at R950.00 per delegate. Non attendance will be charged at the full course cost.<br></br>                 
Should full payment not reflect in our bank account, proof of payment may be requested on registration of the course.               
<p></p>
<p></p>

</table>        
        
          <table width="100%" border="0">
                    <tr>
                        <td class="table-heading2" width="340px">Delegate Name</td>
                        <td class="table-heading2" style="text-align:center" width="150px">Dietary Requirements</td>
                        <td class="table-heading2" style="text-align:center" width="60px">Delegates</td>
                        <td class="table-heading2" style="text-align:center" width="170px">Payment Status</td>
                    </tr>
                    <apex:repeat value="{!delegates}" var="cw">
                    <tr class="table-text">
                        <td>{!cw.Contact__r.Name}</td>
                        <td style="text-align:center">{!cw.Dietary_Requirement__c}</td>
                        <td style="text-align:center"><apex:outputText value="{0,number, ###,###}">
                                <apex:param value="{!cw.No_of_Delegates__c}"/>
                            </apex:outputText>
                        </td>
                        <td style="text-align:center">{!cw.Payment_Status__c}</td>
                                            </tr>
                    </apex:repeat>
                  
 </table>
 <br></br>
 <br></br>
 <br></br>
<h3>Training Venue:</h3>                
<table>
    <tr><td></td><td></td><td>{!event.Venue__r.Name}</td></tr>
    <tr><td></td><td></td><td>{!event.Venue__r.Address__c}</td></tr>

</table>
<br></br>
<br></br>
If you have any queries, please don't hesitate to contact us.

 </html>
</apex:page>

 

The Controller:

public class TrainingConfirmation{

    private Account account;
    public ID AccountID {get; set;}
    public List<CQS_Delegate__c> delegate = new List<CQS_Delegate__c>();
    
     private CQS_Event__c event;
     public Id eventid;
     public Id accountpassedid;
          
   public PageReference genConfirm() {  
   PageReference result=new PageReference('/apex/atrainingfconfirmation2');
      result.getParameters().put('eventid', event.id); 
      result.getParameters().put('company', accountId); 
   return result; }
 
 
    public TrainingConfirmation(){
        eventid  = ApexPages.currentPage().getParameters().get('eventid');        
        accountpassedid  = ApexPages.currentPage().getParameters().get('company');        
        event= [SELECT Id, Name,Start_Date__c,Venue__r.Name,Venue__r.Address__c FROM CQS_Event__c WHERE Id = :eventid limit 1];  

        
    }
            
    public CQS_Event__c getevent(){
        return event;
    }
          
   public List<CQS_Delegate__c> getdelegates(){
        delegate = [SELECT Contact__c,No_of_Delegates__c,Contact__r.Name,Dietary_Requirement__c,Account__r.Name,Payment_Status__c from CQS_Delegate__c WHERE Event__c =:eventid and Account__c=:accountpassedid];
             return delegate;
    }
    
    
    
    public List<SelectOption> accounts    {  
    get    {
     if (accounts == null) {
        accounts = new List<SelectOption>();
        List<Account> citylist = new List<Account>();  
        citylist = [Select Id, Name from Account where ID IN (Select Account__c from CQS_Delegate__C where Event__C =:eventid) ];  
        for (Integer j=0;j<citylist.size();j++)  
        {      
        accounts.add(new SelectOption(citylist[j].ID,citylist[j].Name));  
        }  
    }
   return accounts;
   }
    set;
}

}

 

Many thanks for any help!!

Ross

Best Answer chosen by Admin (Salesforce Developers) 
SantoshiSantoshi

You will be able to get any variable of the class even accountid, need not to pass parameter in url. Just redirect to the second page as I have said and directly access the value... You can try..

All Answers

SantoshiSantoshi
Hi.You dont even need to pass the parameter from one page to other if you are using the same controller.Just change the way your are redirecting on the page2.It should be PageReference result=Page.atrainingfconfirmation2; return result. By redirecting in this way you can directly get the eventId in the controller when the second page is loaded.
rosscorossco

Thanks, but I am trying to get the accountid they have selected from the list - not the eventid.

Ritesh AswaneyRitesh Aswaney

Wondering if you pass it using <apex:param> within the <apex:commandLink> to set an instance variable in the controller should solve this.

 

<apex:commandLink value="..." action="{!.....}">

                 <apex:param name="XXXX" value="{!ZZZ}" assignTo="{!Var}" />

</apex:commandLink>

aballardaballard

As mentioned above, since both pages use the same controller you do not need to pass parameters via the url.   You can just use variables within the controller.

 

But if you really need to use the url approach you need to set the redirect option on the page reference to force redirecting to the new page.  Otherwise the switch happens entirely within the server and the url does not change.  

 

But you don't need to do this.   And reidrecting means an extra round trip to the browser.  And exposes the parameters in plain text which might be a security concern in some cases. 

SantoshiSantoshi

You will be able to get any variable of the class even accountid, need not to pass parameter in url. Just redirect to the second page as I have said and directly access the value... You can try..

This was selected as the best answer
rosscorossco

Thanks Guys - your help is much appreciated. I have learnt that I can simply access the variables in the controller. Voila!