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
Hugh Wheeler 8Hugh Wheeler 8 

Filtered Lookp in Visualforce Page

Hi,

I have a table on a visualforce page.  The table displays columns from a custom object.  One of the columns is a filtered lookup based on two of the other fields in the table. 

I have an add row button that adds blank rows to the custom object in the custom controller.  These objects are not saved until the user hits an update button.

The Filtered lookup displays fine on those records that have been saved, but not on the records that have not yet been saved.  In the VF page however the lookup is blank until the row has been saved.  This is slightly different behaviour than in a standard page which shows the correct values in the page dynamically.

Has anyone come across this before, and is there an easy way to solve it?
Mudasir WaniMudasir Wani
Hi Hugh,

Are you using input fields.
Can you paste the sample code here.

 
Hugh Wheeler 8Hugh Wheeler 8
Ok the relevant parts of my Visual force table are as follows:


<apex:pageblockTable id="theTable" value="{!timetableList}" var="field" cellPadding="4" border="1" rowClasses="odd,even" styleClass="tableClass">

 <apex:column style="{!if(field.isConflict,'background-color:red;', 'color:black')}"> <apex:facet name="header">Cycle Week</apex:facet> <apex:inputField value="{!field.timetable.Timetable_Period_Cycle_Week__c}"/> </apex:column>

<apex:column style="{!if(field.isConflict,'background-color:red;', 'color:black')}"> <apex:facet name="header">Day</apex:facet> <apex:inputField value="{!field.timetable.Timetable_Period_Day_Name__c}"/>

<apex:column style="{!if(field.isConflict,'background-color:red;', 'color:black')}"> <apex:facet name="header">Start Session</apex:facet> <apex:inputField value="{!field.timetable.Timetable_Start_Period__c}"/> </apex:column>

<apex:column style="{!if(field.isConflict,'background-color:red;', 'color:black')}"> <apex:facet name="header">End Session</apex:facet> <apex:inputField value="{!field.timetable.Timetable_End_Period__c}"/> </apex:column>


 </apex:pageblockTable>

In bold are the fields which determine the values that should appear in the filtered lookup.  In italics are the two filtered lookups.

The filter on each is:

(Class Timetable: Day NameEQUALSFirst Session ID: Day Name) AND (Class Timetable: Cycle WeekEQUALSFirst Session ID: Cycle Week)
(Class Timetable: Day NameEQUALSLast Session ID: Day Name) AND (Class Timetable: Cycle WeekEQUALSLast Session ID: Cycle Week)


-------------------------------------

The timetableList object that the table is based on is a wrapper object specified as follows:

public Class TimetableWrapper{
    public Boolean isSelected{get;set;}
    public Class_Timetable__c timetable{get;set;}
    public String personKey {get;set;}
    public String roomKey {get;set;}
    public String personRoomKey {get;set;}
    public Boolean isConflict {get;set;}
}

The add row to the table functionality is triggered by a command button


<apex:commandButton value="Add 1 Rows" action="{!addRow}" reRender="out">
    <apex:param name="addRowNumber" value="1" assignTo="{!addRowNumber}"/>
</apex:commandButton>


The method that adds the row into the table is:

public void addRow()
    {
        for(Integer i=0; i<addRowNumber; i++)
        {
            TimetableWrapper newRow = new TimetableWrapper();
            timetableList.add(newRow);
        }
    }

I hope this help, is I can provide any additional info, let me know.
Mudasir WaniMudasir Wani

Hi Hugh,

As you are fetching the date using custom controllers.
You need to use with sharing keyword to force the  sharing rules

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_keywords_sharing.htm
 
public with sharing class TimetableWrapper{

// Code here

}


Donot forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
Hugh Wheeler 8Hugh Wheeler 8
Thanks for the information.

with sharing on the wrapper made no difference.

Hugh
Hugh Wheeler 8Hugh Wheeler 8
The problems seems to be more that it doesn't seem to refresh the filter when you change the values on the VF page.
Mudasir WaniMudasir Wani
Hugh you are correct that is the reason you are having the problem.
See if this can help 
https://www.minddigital.com/how-to-create-dynamic-dependent-picklist-of-objects-within-salesforce/

Donot forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
 
Hugh Wheeler 8Hugh Wheeler 8
This is for dependent picklists.  The problem I have is Filtered Lookup fields.  I could turn it into a select, and manage the filter through code, but I expected using an input field that this would work without having to jump though hoops.  I really thought the answer would be in forcing a refresh of that column somehow.
Mudasir WaniMudasir Wani
I am very much interested to know the solution or any workaround.
I will try to play with the code.
surasura
hi Hugh ,

I think you need to  rerender relvant row at the onchange event of controlling lookup .you can use a actionsupport function for this purpose.
<apex:column id="weekcolumn" style="{!if(field.isConflict,'background-color:red;', 'color:black')}"> 
 <apex:facet name="header">Cycle Week</apex:facet> 
 <apex:outputpanel id="weekpanel"
  <apex:inputField value="{!field.timetable.Timetable_Period_Cycle_Week__c}"> 
   <apex:actionsupport event="onchange" rerender="{!$Component.weekpanel},{!$Component.daypanel}"  />
   </apex:inputfield>
  <apex:outputpanel>  
</apex:column> 

<apex:column id="daycloumn" style="{!if(field.isConflict,'background-color:red;', 'color:black')}"> 
 <apex:facet name="header">Day</apex:facet> 
 <apex:outputpanel id="daypanel">
 <apex:inputField value="{!field.timetable.Timetable_Period_Day_Name__c}"/>
 </apex:outputpanel>
<apex:column>

give this a try by replacing your 2 highlighted columns . Hope I understand you problem . if not apologies
Hugh Wheeler 8Hugh Wheeler 8
Ok I managed to solve it.  Quite a silly mistake in the end.


public void addRow()
    {
        for(Integer i=0; i<addRowNumber; i++)
        {
            TimetableWrapper newRow = new TimetableWrapper();
             Class_Timetable__c myTT = new Class_Timetable__c()
             newRow.timetable = myTT;

            timetableList.add(newRow);
        }
    }

I was repeating across a wrapper object to create my table.  The rows in the table were based on the timetable variable inside the wrapper but I hadn't populated that variable with anything.

As soon as I added the two highlighted rows above the page started working perfectly.