You need to sign in to do that
Don't have an account?
raj161
Get the value from lookup field on Visulaforce
Hi,
I have kept a look up field in the visualforce page using the following code.
<apex:inputfield value="{!Account.Associated_Global_Account__c}"/>
The lookup field works good but when a user enter the information in the lookup field I am unable to capture it on the apex side.
I am not sure how to capture a value from the lookup field from the visualforce page.
You need to have it posted back to the supporting controller. By simply populating that inputfield in the page won't set the apex controller properties. Do you have the user click a button, for example within an apex:form? Put a simple button on the page that calls an apex controller method. You should see the value then.
Perfect!!!.
Thank U.
hi raj,
I am facing the problem how to capture the lookup filed value in apex controller.u got the solution plz give me example code.
Thanks in advance,
manu...
Please make sure you include the standardcontroller code in apex page....I was missing this at first...:)
the code goes like this...
public GlobalAccountContacts(ApexPages.StandardController controller) { Id id = ApexPages.currentPage().getParameters().get('id'); this.act=(account)controller.getRecord(); }
Let me know if any confusion....
Thank u so much for ur reply,
I have 2 VF pages with three common fileds.So i dont want to enter the common values again in second VF page.So for first filed i can catch the value through lookup.once i catch the value i want to populate the vaues of remaining two fileds of corresponding lookup value by clicking on command link.To populate the values i have to capture the lookup value in controller with out saving the record.By using getRecord() we can get the saved record value.
I am using standard controller only.
I should implement this concept in many pages.plz tell me how to capture the lookup filed value in controller without saving the record.
Thanks in advance,
Manu
Hi aalbert,
dats great to see that u could find a solution to pass a lookupfield value from the vpage to controller, actually iam having a similar issue...plz help me in solving it..
my code is as follows....
<apexage standardController="CAF_Bank__c" extensions="lookup3">
<script>
function branchpopulate()
{
<!-- here iam trying to fetch the list which is having queried output ie branchname field value corresponding to record whose branchcode value==lookup field value values -->
var myArray = new Array();
myArray= '{!CurrentBranchList}'.replace('[','').replace(']','').split(',');
var currbranchname=myArray;
alert(currbranchname);
<!--but currbranchname is displaying some strange values but not the exact branch name corresponding to a record which i queried in d controller so plz correct me how to do this task of fetching that record related to my lookup field value and populate those values to ui ie visualforce page....--> document.getElementById('{!$Component.form1.branchname}').value=currbranchname;
<!--here iam popuilating branch code value to the visualforce page inputfield value-->
return false;
}
</script>
<apex:form >
<apexageBlock title="My Content">
<apexageBlockSection title="My Content Section" columns="2">
<apexageBlockSectionItem >
<apexutputLabel value="BranchCode" for="theLookup"/>
<apex:inputField id="theLookup" value="{!CAF_Bank__c.caf_lookup__c}" />
<!--i want to pass this lookup field valuue to my controller so i have to filter query using this value,but iam not able to pass it i am able to pass textfield value using setters and getters but iam not able to pass this lookup fielsd value plz tell me how to pass this value to controller -->
</apexageBlockSectionItem>
<apexageBlockSectionItem>
<apexutputLabel value="Bank Name"/>
<apex:inputField id="bname" value="{!CAF_Bank__c.Bank_Name__c}"/>
</apexageBlockSectionItem>
<apexageBlockSectionItem >
<apexutputLabel value="Branch Name "/>
<apex:inputField id="branchname" value="{!CAF_Bank__c.Branch_Name__c}"/>
</apexageBlockSectionItem>
</apexageBlockSection>
</apexageBlock>
<apex:commandButton value="autopopulating" onclick="branchpopulate()"/>
</apex:form>
</apexage>
My controller is as follows:
So finally what iam trying to do here is just passing lookupfield value to controller and query the record related to that lookupfield value and pass thiss queried output to vpage and automatically populate those values to the input fieldsup onselecting any lookup field value in vfpage..
So bob if iam not clear to u abt my requirement plz let me know.and plz correct my mistakes so that io can fulfil my requirement...
So hope iam going wrong in passing lookup field value,since its not passed plz correct me in passing the lookupfield value to the controllerr....
Thanks&Regards,
Anu....
Hi raj,
plz give me complete example for capturing the lookup value in apex side and to dispaly agian that lookup value in vf page by clicking on the button.So that i can understand.I am new to apex and vf.plz help me.
Thanks in advance,
Manu..
VF Code....
In the below code {!Account.Associated_Global_Account__c} is the lookupvalue.
<apex:page tabStyle="Global_Account_Team__tab" standardController="Account" extensions="GlobalAccountContacts" showHeader="true" sidebar="false">
<apex:form >
<apex:outputLabel style="font-weight:bold;" value="Account Name :"></apex:outputLabel>
<apex:inputField id="accountName1" value="{!Account.Associated_Global_Account__c}"/>
<apex:commandButton value="Search" action="{!Search}"/>
The related controller code is here..
GlobalAccountContacts
public GlobalAccountContacts(ApexPages.StandardController controller) { Id id = ApexPages.currentPage().getParameters().get('id'); this.act=(account)controller.getRecord(); } String AccountId; AccountId = act.Associated_Global_Account__c;
Hi,
Can someone guide me through the steps of saving value from a textbox to database in Force.com. I have two textboxes - Product Name and ProductID and two buttons- Save & Get.
When Save button is clicked - value in Product Name textbox is saved in database and when a value is inserted in ProductID textbox and Get button is clicked corresponding ProductName is fetched from database in the Product Name textbox.
Basically I am looking for steps of simple data save and retrieval