I have public Opportunity destOpp {get; set;} in my apex code.

I have <apex:inputField label="Source Account" value="{!sourceOpp.AccountId}" /> in my vf page.

After I select an account from the the vf page using the magnify glass then I click a button called "Get Source Contact" I want to use the accountId to get the list of associated contacts.

Currently I have an id hard code to confirm that the button retrieves the related contacts and displays them on the page for me. I need to get the accountid dynamically; however, the value of destOpp.AccountId is null!

I see a few javascript examples but they seem to be incomplete in the code for me to fully understand how to make it work.

  • The market for the VF page didn't show in my question!!! Let me try again without the <>. apex:inputfield label="Source Account" value="{!sourceOpp.AccountId}" To be clear, I do not want the data from the lookup to be updated. I am just trying to use the cool feature of the look up to allow the user to find an account name with point and click, then I need the associated accountID to build out my Contact query WHERE clause. Hope this makes sense. May 15 '16 at 16:55
  • Welcome to SFSE. Please use edit to amend your post and add your controller and VF page; Follow the instructions at How to Ask to get tips on formatting and succintness
    – cropredy
    May 15 '16 at 17:15

destOpp.AccountId isn't bound to your Visualforce page (the {!...} syntax). It would work just fine if you changed your Visualforce code to:

<apex:inputField value="{!destOpp.AccountId}" />
  • I didn't put the code correctly. I didn't paste the correct field with the associated mark up. I have both sourceOpp and DestOpp and the appropriate mark up. The issue from what I have read is that I don't really want these fields bound to a real record. I want the benefit of looking up to account which that works out of the box. I have seen Javascript examples but they don't include a full easy to understand example that gets the lookup id from the field lookup inputField and passes it to the controller. That is what I think I need to get it to work. I don't know Javascript well enough. May 15 '16 at 22:45
  • I could send the entire controller and vf page if that would help you help me. Just let me know where I can send to. May 15 '16 at 22:52
  • @EagertoLearn You can use any variable you want. A "record" in memory isn't the same as a record in the database. You can call your variable "fakeOpp" or whatever you want to. Just remember to bind the correct variable to the inputField in Visualforce. In your controller, make sure you're querying using whatever variable you end up binding to. Perhaps you could make a gist and we can work from there?
    – sfdcfox
    May 15 '16 at 23:13
  • Code is at the link below with explanation of what it is I am trying to do and how the current state is working. gist.github.com/Uncrasher/6f0c55fbb00fe55a6d548226ec536780 May 17 '16 at 0:41
  • Hi sfdcfox - any change to look at the code to help me past this issue? It seems like I can't get the table to update with the data in the account fields. I tried removing look up fields and put inputText and entered ID values and it still only works the first time I click the get contacts button. May 17 '16 at 20:04

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.