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
Abhishek KedariAbhishek Kedari 

Showing Owner field value on visualforce page

Hi All,

      I have created visual force page and I want to show owner field of the object on this page for which I created this page.
      I tried different ways mentioned below but it did not work. I am able launch the page but owner field remains blank where as other fields works fine.
      Other fields are custom fields and owner field is standard field     

      My code is like this - 

      Visualforce page :
              ( Not complete code just important one) 
<apex:page standardController="Shipments__c" extensions="shipment">
       <apex:inputField value="{!shipment.Related_Opportunity__c}"/>
       <apex:inputField value="{!shipment.Basis_Technical_Contact__c}"/>
       <apex:outputField label="Owner" value="{!Shipments__c.Owner.name}"/>
  I also tried replacing value of fields to :

<apex:outputField label="Owner" value="{!Shipments__c.Owner}"/>           // with controller name 
<apex:outputField label="Owner" value="{!Shipments__c.Ownerid}"/>        // with controller name
<apex:outputField label="Owner" value="{!Shipments.Owner}"/>                 // using object name
<apex:outputField label="Owner" value="{!Shipments.Ownerid}"/>             // using object name

and My controller class is :
public class shipment {

   public Shipments__c shipment{get;set;}

    public shipment(ApexPages.StandardController controller) {
         shipment = new Shipments__c();
    }
}

Is this because I am creating new object and new object contains all null values initially ?
How I can get owner name on my vusalforce page ?
When I use standard layout for creating new object provided by salesforce without using visualforce page, I do see owner field gets populated properly.
Please help.

Thanks,
Abhishek

Best Answer chosen by Abhishek Kedari
Virendra ChouhanVirendra Chouhan
Hi Abhishek, Every LookUp field store Id of the related object's record and its string type. So just get UserId and put them into the Owner Field og that object. I.e. account.owner = UserInfo.getUserId(); Regards Virendra --- Original Message ---

All Answers

Virendra ChouhanVirendra Chouhan
Hi Abhishek,

Yes you are right because shipment is used for creating new record so initially it contains null values.

so if you want to show Owner name then use $User or $UserInfo.
i.e
 {!$User.FirstName} same as Last name {!$User.LastName}

Or in Controller you can use :
public string u{get;set;}
      u = Userinfo.getName();
And access u in Vf page 
Let me know it helped or not.

Regards
Virendra
Abhishek KedariAbhishek Kedari
Hey Virendra,

Its working great.  :-)
May I know when I save this object, How I can assign this value to the owner field.
Because owner field is not a field of type string. It requires object of type Lookup(User,Queue)
How to get the value of user which I can store in owner field.

Thanks,
Abhishek
Virendra ChouhanVirendra Chouhan
Hi Abhishek, Every LookUp field store Id of the related object's record and its string type. So just get UserId and put them into the Owner Field og that object. I.e. account.owner = UserInfo.getUserId(); Regards Virendra --- Original Message ---
This was selected as the best answer