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
TH53TH53 

Bug with Dynamic Visualforce Binding - getting no assistance from salesforce support

So, I believe i have found what appears to be a bug with the new Dynamic Visualforce Binding. I created a case with all the information, but unfortunately since i don't have 'premier' status, Salesforce will not even take a look at the issue. Therefore, I am reaching out to my awesome force.com developers out there to see if anyone else has encountered something similar. Maybe i will get lucky and find someone with 'premier' status to help out.

Here's the situation: I have built a Visualforce page with a component that contains an apex:datatable. As part of the datatable definition, I have a set of dynamically defined columns. In each column i have an apex:outputField that uses Dynamic Visualforce Binding to specify the value:

<apex:outputField value="{!pos.Obj[col.FieldName]}" />
    where 'pos.Obj' represents the row object and
    'col.FieldName' represents the API name for the associated field.

If the FieldName is a field directly on the object (example: FirstName), everything works fine in all situations.

If the FieldName is a field from a referenced field on the object (example: Owner.FirstName or ReportsTo.Email), then salesforce will throw an 'Insufficient Privileges' error if there are records in the list where the referenced item is null. If all records in the list have a value in the referenced field, then the list displays correctly.

To illustrate: if the FieldName is 'ReportsTo.Email', then if all Contacts in the results list have a value in the ReportsTo field, the page displays correctly.

If any one of the Contacts in the results list has a null value in the ReportsTo field, then the page displays an 'Insufficient Privileges' error.

Seems to me they have an issue binding to field values on a referenced object when that referenced object happens to be null for a particular record.

Thanks in advance for any help/assistance you can provide.

TH53TH53

So - i am extremely convinced that this is a bug in how salesforce resolves field values when dynamic visualforce binding is used and the field specified is one that resides on a referenced object. Therefore, I created a very simple example to prove my findings. The outcome is the same - if the reference field has a value, then saleforce is able to resolve the field value on that referenced object; if the reference field is null, then an error is thrown. In my new simple case, a different error is thrown than the one I mention above.

 

The sample field I am using is the Manager (reference) field on the User object.

The field i want to dynamically bind is the email field on the Manager (reference) field.

Example: User->Manager>Email

 

On my sample test page, I have the following:

 

<apex:repeat value="{!listUsers}" var="u" }" >

         <apex:outputField value="{!u.obj['Manager.Email']}" />
         <apex:outputField value="{!u.obj[ManagerEmailField]}" />

</apex:repeat>

 

where:

          u = variable representing the current item in the list

          obj = the field on the list item, defined as a User.

 

In the first outputField, I am statically hard-coding the field name = 'Manager.Email'

In the second outputField, I am using an attribute called ManagerEmailField that returns the value 'Manager.Email'

 

In theory, there should not be any difference in the result. However, if all results in the list have a value in the Manager field, then it works great. If just one of the items in the list does NOT have a Manager field, then the system displays the following error:

 

Could not resolve field '' from <apex:outputField> value binding '{!u.u[ManagerNameField]}' in page fonadirectory

 

If i remove the second outputField, then there is no error. So, there doesn't seem to be a problem with the hard-coded field definition.

 

Conclusion: there is a problem when using Dynamic Visualforce binding when you use a field from a referenced object. The Salesforce documentation clealy states that this is supported : Bothreferenceandexpressioncan be complex expressions, such as those that evaluate to object relationships.

       

Anybody out there that has run into something similar? I need to convince Salesforce that this is something that needs to be looked at. The partner support channels are refusing to look into the matter. 

 

 

TH53TH53

Some additional information:

 

To demonstrate the issue I have encountered, I took the code sample provided by Salesforce.com in their documentation: Using Dynamic References with Standard Objects. The code is located in the section titled: Using Dynamic References for a User-Customizable Page. Here is a link to the page: http://www.salesforce.com/us/developer/docs/pages/Content/pages_dynamic_vf_sample_standard.htm

 

I made two slight modifications:

  1. Added a wrapper class around the field list. So, instead of a list of field names, we have a list of class objects that contain not only the API field name, but an additional attribute used for styling purposes.
  2. Instead of using the Case object, I am using the Contact object with the ReportsToID reference field and associated ReportsTo.name and ReportsTo.email fields.

Here is the page definition:

<apex:page controller="DynamicCaseLoader"> 
<apex:form >

    <apex:repeat value="{!contactDetails}" var="contactObj">
        <apex:repeat value="{!contactFieldListObj}" var="cf">
	   <apex:outputPanel layout="block">    
    	        <apex:outputField value="{!contactObj[cf.fieldName]}"  />
	   </apex:outputPanel>
        </apex:repeat>
        <apex:outputText value="------------------------------------------------------------------" />
     </apex:repeat>
	        
</apex:form>
</apex:page>

Here is the controller class:

public class DynamicCaseLoader 
{
    public List<Contact> contactDetails 	{ get; private set; }

    public DynamicCaseLoader() 
    {
	String theQuery = 'SELECT id, name, title, phone, mailingcity, ReportsToID, ReportsTo.name, ReportsTo.email '+
               		   'FROM Contact';
        
        
        // Comment the following line of code and uncomment the line of code after that and the error will not occur.
        theQuery += ' WHERE ReportsToID = null';
        //theQuery += ' WHERE ReportsToID != null';

	contactDetails = Database.query(theQuery + ' LIMIT 50');
    }

    public List<contactFieldWrapper> contactFieldListObj 
    { 
        get {
            if (contactFieldListObj == null) 
            {
                contactFieldListObj = new List<contactFieldWrapper>();
                contactFieldListObj.add(new contactFieldWrapper('name'));
                contactFieldListObj.add(new contactFieldWrapper('title')); 
                contactFieldListObj.add(new contactFieldWrapper('phone')); 
                contactFieldListObj.add(new contactFieldWrapper('mailingcity')); 

                contactFieldListObj.add(new contactFieldWrapper('ReportsToID'));
                contactFieldListObj.add(new contactFieldWrapper('ReportsTo.name'));
                contactFieldListObj.add(new contactFieldWrapper('ReportsTo.email')); 
    
            }
            return contactFieldListObj;
        }
        private set;
    }

    public class contactFieldWrapper 
    {
        public String fieldName 	{ get; set; }
        public String sDisplayStyle  	{ get; set; }

        public contactFieldWrapper( String sName) 
        {
            fieldName = sName;
            sDisplayStyle = 'text-align:left;';
        }
    }
}

 

 

Now, any time you attempt to access the page, you will receive the following error:

Could not resolve field '' from <apex:outputField> value binding '{!contactObj[cf.fieldName]}' in page dynamiccaseeditor

 

If you comment line 12 and uncomment line 13 in the code, and attempt to access the page, you will NOT receive the error. (Make sure you have at least one contact with the ReportsToID field set.) This is because all the contacts displayed will have a value in the ReportsToID field and the outputField can properly resolve the value.

 

Other items of note:

  • If you use outputText instead of outputField, everything works fine if the ReportsToID field is null.
  • If you use a list of field names, instead of a list of class objects containing the field name, everything works fine if the ReportsToID field is null.
  • With a more complex implementation (not this simple sample code), the error renders itself somewhat differently. Instead of the error message noted above, we receive an ‘Insufficient Privileges’ error.
TH53TH53

To cut to the chase - the bug rears its head with the combination of the following elements on a page:

1. Use of Dynamic Binding with a Visualforce apex:outputfield field.

2. Reference to the field name via a field wrapper class.

3. Referencing a field value that exists on a related object where the related object value is null (ex. Contact.ReportsTo->FullName where the ReportsTo field value is null)"

Mitesh SuraMitesh Sura

OK, so I was not alone facing this issue. I thought it was a bug too, now I am convienced it is! 

 

Please look at my post here: http://boards.developerforce.com/t5/General-Development/Dynamic-quot-headerValue-quot-binding-in-VF-page/m-p/487387#M74337

 

I am trying to dynamically set cloumn name, but it just won't work. If I hard code the field names, it works just fine. 

May I know how did you log a case? I beleive there is seperate forum or site to log VF bugs, general help is BS. 

I wouldn't have said that if I had not experienced it first hand. 

 

regards

ISVForce Partner. 

TH53TH53

Yes - this appears to be the same bug.

 

The good news is that with the help of one of Salesforce's premier customers and one of Salesforce's premier consulting partners, we were able to get the attention of some inside folks to re-open the case and look at the issue. I've given them an org to use and sample code i posted to reproduce the error. I will update this post with more info/status when i have it.

 

In the meantime, i will send you a private email with some more info that might be helpful for you.

TH53TH53

After looking at your post a little more carefully, i don't think it is actually the same thing that i am experiencing. Are you getting the same error that I have reported?

 

I do use dynamic visualforce binding to display information in a table with <apex:repeat> used to define the columns (since the number and display information is dynamic). The column header/name is also dynamic. We've never had any issues with displaying the dynamic column names, it is the actual field value that is causing the trouble when we reference a field on a related object. We use outputField, not inputField (not sure if that makes a difference)

 

With that said, salesforce has acknowledged our issue as a bug. They are looking at it now, but cannot tell us if/when it will be fixed.

pandu yadavpandu yadav
Can I get some help on this?
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000Ag5j