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
Shravya Rama 9Shravya Rama 9 

Field visible on Standard Detail Page but not on Visuallforcepage

Hello all,

I have a field Previous__c which is generated from a field update formula and shows the previous value of another field currentfield__c. Previous__c is correctly shown in standard detailpage layout but its null when I try to display it using    
<apex:outputText value="{!object.Previous__c }"/>.  I have also tried apex:outputfield, but its still the same

Can anybody suggest Where am I going wrong?
 
Best Answer chosen by Shravya Rama 9
Sukanya BanekarSukanya Banekar
Hi, 
I have implemented following code for both standard as well as custom controller
Standard controller

<apex:page standardController="Account">
  <apex:outputField value="{!Account.Prior_Email__c}"/><br/>
</apex:page>

To run this pass id in url e.g  /apex/TestAcc?id=0019000001oBT31
 
Custom Controller


<apex:page action="{!load}" Controller="AccPrevious">
  <apex:outputText value="{!objAcc.Prior_Email__c}"/><br/>

</apex:page>

public class AccPrevious{
    public Account objAcc{get;set;}
    public void load(){
        objAcc=[select Prior_Email__c from Account where Name=:'test' limit 1];
    }
}

Please let me know if any of this works for you.

Thanks,
Sukanya

All Answers

Sukanya BanekarSukanya Banekar
Hi,
try using <apex:outputField value="{!object.Previous__c }"/>

Thanks,
Sukanya
Shravya Rama 9Shravya Rama 9
Hi Sukanya,
As I mentioned in my question,i have already used outputfield but its still the same.
Sukanya BanekarSukanya Banekar
Hi,
what are you using standard controller or custom controller?
 
Sukanya BanekarSukanya Banekar
Hi, 
I have implemented following code for both standard as well as custom controller
Standard controller

<apex:page standardController="Account">
  <apex:outputField value="{!Account.Prior_Email__c}"/><br/>
</apex:page>

To run this pass id in url e.g  /apex/TestAcc?id=0019000001oBT31
 
Custom Controller


<apex:page action="{!load}" Controller="AccPrevious">
  <apex:outputText value="{!objAcc.Prior_Email__c}"/><br/>

</apex:page>

public class AccPrevious{
    public Account objAcc{get;set;}
    public void load(){
        objAcc=[select Prior_Email__c from Account where Name=:'test' limit 1];
    }
}

Please let me know if any of this works for you.

Thanks,
Sukanya
This was selected as the best answer
Shravya Rama 9Shravya Rama 9
Hello Sukanya,
I got the point what you are trying to accomplish but even this doesnt work. Its because the prior_Email__c has a value only after the first edit. And when you try to retrieve a null value at the first instance, it throws a null exception error.
Shravya Rama 9Shravya Rama 9
And am using a custom controller.
Sukanya BanekarSukanya Banekar
Hi Shravya,
If possible please paste your code in comment so that I can give you proper solution.
Shravya Rama 9Shravya Rama 9
Hello Sukanya,
Thank you so much. Its working fine. As I said value for the Previous_Selected_Fahr__c exists only after an edit. So I over rided the edit button with new vf page and let my new button go with normal vf page
Here is the final code

Class
public Reservation__c objAcc{get;set;}
public void load(){
objAcc=[select id, Previous_Selected_Fahr__c from Reservation__c where id=:ApexPages.currentPage().getParameters().get('id') limit 1];
}

Page
<apex:page standardController="Reservation__c" extensions="CarsharingEditPage" action="{!load}">
<apex:outputField value="{!objAcc.Previous_Selected_Fahr__c}" />
</apex:page>