Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a Vf page from which i need to fetch the value of new owner and need to save the value in property defined in controller:

Following is my vf page code:

    <apex:InputField label="user" value="{!a.ownerid}"/>

here a is object of opportunity

Controller code:

used one property to store the value:

public string ownername {get;set;}

Note: user will input the value through lookup field.

Any suggestions on this?

share|improve this question

When you submit the page, Visualforce will update the OwnerId field of your opportunity object a automatically for you. If you want to use that value elsewhere (e.g. in a save method), you can just reference the value directly:

Id newApproverId = a.OwnerId;

and you can query for the corresponding name (if you need that):

String newApproverName = [select Name from User where Id = :a.OwnerId].Name;
share|improve this answer

The inputfield will have a direct binding to the a.ownerid.

This binding is two-directional, so that means two things:

  1. When the page loads, the input field will be filled with a.ownerid.
  2. The reverse is also true: the value of the input field will be saved to a.ownerid. If you had a commandButton with an action that is executed on the controller, the a.ownerid will by then have the value that the user entered on the Visualforce page before the user clicked the commandButton.

Update your Visualforce code like so to include that commandButton

    <apex:InputField label="user" value="{!a.ownerid}"/>
    <apex:commandButton action="{!someAction}" value="Save"/>

Now you can reference a.owernid anywhere in that someAction method on the controller, and use code like this to store it to owername:

public PageReferene someAction() {
    ownername = a.ownerid;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.