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
parkerAPTparkerAPT 

VF Error: Invalid variant 'parent': value 'Contact' w/ StandardSetController [Code Example]

I'm seeing some a strange error in a custom visualforce page that has a Standard Set Controller using a QueryLocator.

 

Overview:

The visualforce page shows an error of "Invalid variant 'parent': value 'Contact'"

The main culprit is calling the StandardSetController setPageSize method

 

Code Example:

 

public class BuggedPageController {
public ApexPages.StandardSetController setController { get; set; }
public Contact m_theContact{get;set;}

public BuggedPageController(Apexpages.StandardController asControl){
m_theContact = (Contact) asControl.getRecord();
// There are zero accounts with the name oxxoxo
setController = new ApexPages.StandardSetController(database.getQueryLocator([SELECT name,id,Owner.Name FROM Account WHERE name='oxxoxo']));
//if(this.setController.getResultSize() > 0 ){
this.setController.setPageSize(5);
//}
}

public List<Account> TheAccounts{
get{
return (List<Account>) this.setController.getRecords();
}
}
}

 

<apex:page standardController="Contact" extensions="BuggedPageController">

<apex:dataList value="{!TheAccounts}" var="oAccount">
<apex:outputText value="{!oAccount.name}"></apex:outputText>
</apex:dataList>

</apex:page>

 

 Detail Explanation and Weird Behavior:

  • Depending on the standard controller, the error message differs.  For example, if the standardController is of type "Task" and the appropriate changes are made in the BuggedPagController, the error message reads: Invalid variant 'parent': value 'Task'

  • When you do not specify an ID in the URL the error does not occur.  However, the standardSetController returns a list of all Accounts.
    • That is to say:
    • The URL: https://c.cs1.visual.force.com/apex/demoBuggedTableBinding?id=003S0000002rsfJ throws the error
    • The URL: https://c.cs1.visual.force.com/apex/demoBuggedTableBinding does not throw an error but shows the top 5 Accounts in the list.
  • The root cause lies somewhere in the setController.setPageSize(5) method call
    • If I comment this method call out or only call it when there are records available, the error does not occur when an ID is specified in the URL
    • If I comment this method call out when there is NOT an ID in the url, the Visualforce page does not display the top 5 Accounts.  It appropriately shows zero.
  • Inside a Unit Test, none of these errors occur:  That is to say, I can construct a BuggedPageController and thus call setPageSize when a QueryLocator returns no records without throwing an error.

 

Current Work Around:

  • Always wrap setPageSize in the following if Block:
  •  

    if(this.setController.getResultSize() > 0 ){
    this.setController.setPageSize(5);
    }

     

Related Forum Posts:

 SetPage Size ignored Where Clause

 

 

Message Edited by parkerAPT on 05-15-2009 10:38 AM
sparkysparky

Hey Parker, did you ever get an answer to this or figure it out?  I'm getting a similar error with a different object.

My post: http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=14806

RalphCallaway.ax615RalphCallaway.ax615

Please log a case with saleforce support if you encounter similar issues.

 

In the case comments reference this as a possible instance of bug W-672711.