+ Start a Discussion
Mandeep DekaMandeep Deka 

How to display Created Date/Last Modified Date along with Owner name as an outputfield?

What I am trying to achieve is shown in the below screenshot.

 

URL: http://imageshack.us/photo/my-images/10/viewdate.jpg/



 what I have written is :

 

<apex:pageBlockSectionItem >
	    <apex:outputLabel value="Created By" for="created__by"/>
	    <apex:outputLabel value="{!createdby}" id="created__by"/> 
</apex:pageBlockSectionItem>

and the extension has a createdby property which only fetches the FirstName, LastName and CreatedDate and merges them together. 

 

But then again the look up on the CompanyName on mouse hovering is not rendered on doing this.

 

Can anyone give some ideas on this?



Mandeep DekaMandeep Deka

Anyone up for this? Need some input to get me going...please, getting some insight would be really helpful.

 

Thanks.

Rehan DawtRehan Dawt

Hi,

 

Just try this:

 

Class Code: accountClass.cls

 

public Account account {get;set;}

 

Page Code: accountPage.page

<apex:page controller="accountClass">

<apex:pageBlockSection title="Account Details">
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Account Owner"/>
                <apex:outputText value="{!account.Owner.Name}"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Last Modified Date"/>
                <apex:outputText value="{!account.LastModifiedDate}"/>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                <apex:outputLabel value="Created Date"/>
                <apex:outputText value="{!account.CreatedDate}"/>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>

</apex:page>

 

Url: https://c.ap1.visual.force.com/apex/accountPage?id='00000000000000'

 

Mandeep DekaMandeep Deka

Hi Rehan,

 

I appreciate your reponse. Sorry but this is the same thing what I did if you look at my query. I want to display the Owner name along with the Created Date and still want to retain the look up on mouse hover on the Owner name. Your solution does not solve that.

 

Thanks for the reply though.

Rehan DawtRehan Dawt

Can u post your whole code so that i can have a look on it, what you have done.

 

Mandeep DekaMandeep Deka

Here it is:

 

View.page

 

<apex:pageBlockSection >
        <apex:pageBlockSectionItem >
	        <apex:outputLabel value="Created By" for="created__by"/>
	        <apex:outputLabel value="{!createdby}" id="created__by"/> 
        </apex:pageBlockSectionItem>
        <apex:outputField value="{!Cost__c.Cost_Amount__c}" />
        <apex:outputField value="{!Cost__c.LastModifiedById}" />
</apex:pageBlockSection>

 and the extension Cost.cls is:

 

public class CostExtension {
	
    public String createdby {get;set;}
    public CostExtension(ApexPages.StandardController controller) {
       Cost__c costObj = (Cost__c)controller.getRecord();
       Cost__c costObj2 = [Select CreatedById,CreatedBy.FirstName,CreatedBy.LastName,CreatedDate from Cost__c where id=:costObj.id];
       createdby = costObj2.CreatedBy.FirstName + ' ' + costObj2.CreatedBy.LastName +', '+costObj2.CreatedDate.format('M/d/yyyy hh:mm a'); 
    }
}

 That's all I have done!

Rehan DawtRehan Dawt

Check this code :

 

Page Code:-

 

<apex:page standardController="Contact" extensions="helloWorld">
    <apex:pageBlock title="Hello{!$User.FirstName}" mode="edit">
        <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Created By" for="created__by"/>
            <apex:outputLabel value="{!createdby}" id="created__by"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputField value="{!Contact.AccountId}" />
            <apex:outputText value="{!Contact.CreatedDate}"/>
        </apex:pageBlockSectionItem>
</apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

 

Class Code:

 

public with sharing class helloWorld
{
    public String createdby {get;set;}
    public helloWorld(ApexPages.StandardController controller)
    {
       Contact costObj = (Contact)controller.getRecord();
       Contact costObj2 = [Select CreatedById,CreatedBy.FirstName,CreatedBy.LastName,CreatedDate from Contact where id=:costObj.id];
       createdby = costObj2.CreatedBy.FirstName + ' ' + costObj2.CreatedBy.LastName +', '+costObj2.CreatedDate.format('M/d/yyyy hh:mm a');
    }

}



 

I hope you had get your answer, just implement .

i have tryout with this code and it works.

 

Thanks.

ErashadErashad

This is the code you want if you need styling and links very close to VF page.

 

<apex:pageBlockSectionItem >
                <apex:outputPanel layout="block">
                <table width='100%'>
                <tr>
                    <td class='labelCol'>Created by:</td><td class='dataCol col02'><apex:outputLink value="{!LEFT(CreatedById,15)}">{!CreatedBy.FirstName} {!CreatedBy.LastName}</apex:outputLink> <apex:outputText value=", {!CreatedBy.CreatedDate}"/>  </td>
                    <td class='labelCol'>Last Modified by:</td><td class='dataCol'><apex:outputLink value="{!LEFT(LastModifiedbyId,15)}">{!LastModifiedby.FirstName} {!LastModifiedby.LastName}</apex:outputLink><apex:outputText value=", {!LastModifiedDate}"/> </td>
                </tr>
                </table>
                </apex:outputPanel>
</apex:pageBlockSectionItem>