+ Start a Discussion

Date field on deleted lookup shows as today (bug?)

Issue: If a parent object is deleted, the Date fields on the now-orphan children show as today in VF when binded using outputFields. If using outputText the proper value (empty) is shown.

2 objects: Car__c is the parent for Part__c

Excerpt from controller (partly pseudo):
public Schema.FieldSetMember[] carFields { get; set; }
public Part__c[] parts { get; set; }

public Controller()
    carFields = list of fields from Fieldset containing Model__c, CreatedDate, Intro_Date__c
    parts = [select Name, Car__r.Model__c, Car__r.CreatedDate, Car__r.Intro_Date__c from Part__c];

Excerpt from VF page (a table with a list of part Names + their corresponding Car info):
<apex:pageBlockTable value="{!parts}" var="part">

    <!-- Part Name -->
    <apex:column value="{!part.Name}">

    <!-- Car Fields -->
    <apex:repeat value="{!carFields}" var="f">
            <apex:outputField value="{!part.Car__r[f]}"/>


The resulting table looks like this:
Name____Model__Created Date__Intro Date
Screw__________5/5/2014______5/5/2014 < CHILD DELETED >
Pedal__________5/5/2014______5/5/2014 < CHILD DELETED >
This seems like a bug to me. Anything I'm missing?

I don't know if this is a bug, but to avoid this kink of issue, I think you should not render the outputFields when there are no parent records, by doing something like:
<apex:outputField value="{!part.Car__r[f]}" rendered="{! !ISBLANK(part.Car__c)}"/>  (and by the way, add the field "Car__c" in the soql query in the controller).
I'm not looking for a workaround. I want to know why a field that shouldn't even exist is having a random value.
Btw, I have narrowed down the issue: this only happens when lookup date fields are referenced through outputFields. If using outputText the fields show up as blank.