Let me 1st start by saying, I have looked all over the net for an answer, could not gt it done. Thought it would be simple. But is not working.

Problem: RoomType variable is not getting set. It is coming in as NULL, which I am passing to my SOQL as a parameter.

Where am I going wrong ? ANy better ideas to resolve this matter?


Page 1

<apex:inputField value="{!Transactions__c.Room_Type__c}" label="Room Type" />
<apex:inputField value="{!Transactions__c.Transaction_Type__c}" label="Transaction Type"/> 
<apex:inputField value="{!Transactions__c.Check_In_Date__c}" label="CheckIn Date"/>

<apex:commandlink id="CLink" value="Check Availability" onclick="window.open('https://na15.salesforce.com/apex/GetAvailableRooms','_blank','height=600,location=no,resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=1', 1)" style="background:#99CCFF; font-weight=bold" >
                         <apex:param name="RoomType" value="{!Transactions__c.Room_Type__c}"/> </apex:commandlink>

In short the Command Link "Check Availability" is opening up another page GetAvailableRooms using windows.open

Page: GetAvailableRooms

<apex:page controller="getAvailableRooms" sidebar="false">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!AvailableRooms}" var="AR">
            <apex:column value="{!AR.Date__c}"/>
            <apex:column value="{!AR.Room_Type__c}"/>
            <apex:column value="{!AR.Room_Number__c}"/>

            <apex:column value="{!AR.Room_Status__c}"/>

Controller: getAvailableRooms

public class getAvailableRooms{
    // ApexPages.StandardSetController must be instantiated
    // for standard list controllers
    public String RoomType {get; set;}

    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {

                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Room_Type__c, Room_Number__c, Room_Status__c, Date__c  FROM Room_Availabiity__c
                    WHERE Date__c >= TODAY AND Room_Type__c = :RoomType
                    //AND Room_Type__c = :RoomType
                    ORDER BY Date__c ASC, Room_Type__c ASC]));
            return setCon;

    // Initialize setCon and return a list of records
    public List<Room_Availabiity__c> getAvailableRooms() {
       RoomType = ApexPages.CurrentPage().getParameters().get('RoomType');

        return (List<Room_Availabiity__c>) setCon.getRecords();


1 Answer 1


You can simply pass the value in the URL itself

<apex:commandlink id="CLink" value="Check Availability" onclick="window.open('https://na15.salesforce.com/apex/GetAvailableRooms?RoomType="{!Transactions__c.Room_Type__c}"','_blank','height=600,location=no,resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=1', 1)" style="background:#99CCFF; font-weight=bold" >

Also since you are passing from one page to other its better to pass as URL as encoded string and then url decode at other end

  • Mohit Between the time I posted the question and you posted the reply, I tried what you mentioned. Unfortunately, the commandLink does not work the 1st time I lick. RoomType is passed as blank. Strangely enough when I click on the Link 2nd time, it does get passed. Not sure why. Also since the inputField is a Lookup Field it is passing the RoomType ID, which is still fine by me. But the bigger question is why does the value not get passed when I click the 1st time. I did not think, this would be such a big hassle. Any other ideas? Any other way of doing this ?
    – user7128
    Mar 2, 2014 at 5:57
  • use href of html instead .But it is strange that it does not work on first time .. Mar 2, 2014 at 10:09

You must log in to answer this question.

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