-2

I have a inputfield of type lookup. It should contain Id of the reference Account but it takes the Name. Alert is showing name of the Account, where it should return Id. Please Advise.

<apex:inputField id="ShareInputField" value="{!Form_Requests_abv__c.Account_abv__c}"> 

enter image description here

Alert Showing null Account Id

  • try alerting {!Form_Requests_abv__c.Account_abv__c} it should show an Id – Oles Malkov Feb 22 '16 at 12:14
  • I tried this, But it is returning Null – user59759 Feb 22 '16 at 12:17
  • This is because you probably have not submitted the form yet. Why do you need to pass value to a controller with Javascript? Once you set the lookup and press some button or link on your form Id that you are looking for should be available in controller as Form_Requests_abv__c.Account_abv__c. – Oles Malkov Feb 22 '16 at 12:23
  • I have a Dependent Address SelectList, that will contain Address of the Account selected from the LookUp dialogue. So i need here the ActionSupport to pass the Account Id in controller and retrieve the corresponding Address IDs – user59759 Feb 22 '16 at 12:28
2

On your visualforce page, can you try

<apex:actionSupport event="onchange" action="{!accountSelected}"/>

And then once you select an account it will be available in your controller

public void accountChanged(){
    System.debug('----->' + Form_Requests_abv__c.Account_abv__c);
    // Your other logic here to retrieve address Ids
}
| improve this answer | |
  • ya thats i'm doing...but i also need to select the Address of that account from the UI itself for that i need to pass account Id in such way inorder to fetch associated address ids – user59759 Feb 22 '16 at 13:00
  • I'm not sure that I understand what you want with that Id. Why can't you fetch associated address ids in your controller once Account was chosen? If you don`t want the whole page to be refreshed on account change you might want to use ActionRegion for Account and Address. – Oles Malkov Feb 22 '16 at 13:12
  • I've used ActionRegion...but thats not my question...i'm unable to understand how a lookup type Inputfield is returning Account Name i. e string type here. – user59759 Feb 22 '16 at 13:16
  • It is returning ID. But this id is stored in a hidden field on your form. For example go to detail page of some account and copy its ID, then go back to your page and select that account with a lookup. Right click and press inspect in your browser to open page code and press Ctrl+F(search on a page) and paste there Id of selected Account. It will show you where the Id is stored. So string is stored only in UI for user convenience. – Oles Malkov Feb 22 '16 at 13:34
1

This is the normal behaviour for apex:inputField try to use apex:inputText

| improve this answer | |
  • This one is a Lookup field and I want that Lookup icon to appear, so that onclicking a lookup dialogue box will open and allow the user to choose from a list of Accounts. Using InputText will not serve this purpose – user59759 Feb 22 '16 at 12:07
  • Ok, I didnt mentioned that Id will contain in your field Form_Requests_abv__c.Account_abv__c and on UI you will see a Name of the record. So in APEX in field Form_Requests_abv__c.Account_abv__c you will see Id of the record – pklochkov Feb 22 '16 at 12:12
  • In the Alert when I print This.value it is showing the Account Name not the Account Id. But ideally it should print AccountId – user59759 Feb 22 '16 at 12:15
  • To get id just place '{! Form_Requests_abv__c.Account_abv__c}' into JS with quotes. It will work if it is a lookup. Lookup fields are storing Id value in SF database – pklochkov Feb 22 '16 at 13:10
  • yes i've tried this ..it is returning Null – user59759 Feb 22 '16 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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