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
asadim2asadim2 

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.


Scenario:
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:column>
            <apex:outputField value="{!part.Car__r[f]}"/>
        </apex:column>
    </apex:repeat>

</apex:pageBlockTable>

The resulting table looks like this:
Name____Model__Created Date__Intro Date
=======================================
Gear____Benz___4/9/2013______1/4/2013
Knob____BMW____6/8/2012______6/7/2012
Screw__________5/5/2014______5/5/2014 < CHILD DELETED >
Pedal__________5/5/2014______5/5/2014 < CHILD DELETED >
Bushing_Audi___3/5/2011______________
This seems like a bug to me. Anything I'm missing?

Abdel-Ali BOULIKAAbdel-Ali BOULIKA
Hi,
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).
asadim2asadim2
I'm not looking for a workaround. I want to know why a field that shouldn't even exist is having a random value.
asadim2asadim2
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.