Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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:pageBlockSection>
    <apex:InputField label="user" value="{!a.ownerid}"/>
</apex:pageBlockSection>

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

2 Answers 2

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:pageBlockSection>
    <apex:InputField label="user" value="{!a.ownerid}"/>
    <apex:commandButton action="{!someAction}" value="Save"/>
</apex:pageBlockSection>

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

 
discard

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.