1

Im having trouble getting the Financial_Account__c lookup field to display properly on my visualforce page. I am loading a wrapper class that contains Financial_Account_c and Holding_c. The Holding__c object has a lookup on it to Financial_Account_c. Im unable to get the field to display like it should as an inputField through Holding_c.Financial_Account__c nor directly to Financial_Account__c. All suggestions are appreciated.

Controller

public class ctrl {

    public list<holdingsWrapper> holdingList {get;set;}
    public list<Holding__c> holdingResults {get;set;}

    public ctrl(){ 
        this.init();
    }

    private void init(){

        holdingList = new list<holdingsWrapper>();

        String mhQuery = 'SELECT Name, '; 
        mhQuery += 'Financial_Account__c, ';
        mhQuery += 'Advisor_ID__c ';
        mhQuery += 'FROM Holding__c ';

        holdingResults = Database.query(mhQuery);

        for(Holding__c m : holdingResults) 
        {
            holdingList.add(new holdingsWrapper(m.Financial_Account__r, m));
        }

    }

    public class holdingsWrapper
    {
        public Financial_Account__c fa {get; set;}
        public Holding__c maho {get; set;}

        public holdingsWrapper(Financial_Account__c a, Holding__c mh)
        {
            fa = a;
            maho = mh;
        }
    }

} 

Visualforce Page

<apex:page controller="ctrl" title="Financial Accounts" sidebar="false">

<apex:form id="myMHForm">
    <apex:outputPanel id="formPanel" layout="inline">

        <apex:pageBlock title="Financial Accounts" id="muselectedlist"> 

            <apex:pageBlockTable value="{!holdingList}" var="mhItem" id="pgTable1">

                <apex:column headerValue="Financial Account" id="movetoaccount">
                    <apex:inputField value="{!mhItem.fa}" />
                    <!-- <apex:inputField value="{!mhItem.maho.Financial_Account__c}" /> -->
                </apex:column>
            </apex:pageBlockTable>

        </apex:pageBlock>

    </apex:outputPanel>
    </apex:form>

</apex:page>

ISSUE 1: The following does not allow me to save my VF page:

<apex:inputField value="{!mhItem.fa}" />

ERROR: Save error: Could not resolve the entity from value binding '{!mhItem.fa}'. can only be used with SObjects, or objects that are Visualforce field component resolvable. line 0 Force.com save problem

ISSUE 2: The following version saves, but only displays text and NOT the input field with the magnify glass:

<apex:inputField value="{!mhItem.maho.Financial_Account__c}" />

How do I get the field to display properly?

All suggestions are appreciated!

  • 1
    mhList in your VF Page refers to hodlingList in your controller is it? copy paste mistake? – highfive Apr 2 '14 at 3:29
  • You are correct. Thank you for pointing that out! Ive corrected that – user2774325 Apr 2 '14 at 3:53
  • What you expect from Holding_c.Financial_Account__c rather than just having Financial_Account__c? If it's a lookup field the second option it will give you magnify galss. – highfive Apr 2 '14 at 5:10
  • What is the purpose of adding relationship field m.Financial_Account__r to the Wrapper class constructor ? – codebandit Apr 2 '14 at 6:42
  • I was trying to add related fields from the Financial_Account__c object. I was unable to pull the fields through the Holding__c object. – user2774325 Apr 3 '14 at 18:51
2

ISSUE 1 :
You are trying to bind an instance of Financial_Account__c to the inputField as per your wrapper class (your fa is type of Financial_Account__c). This doesn't make sense with an inputField. See the value attribute here in the documentation. You have to bind a field of an object as the value

ISSUE 2 :
You can directly bind the holdingResults list since the Financial_Account__c is a lookup.

<apex:pageBlockTable value="{!holdingResults}" var="mhItem" id="pgTable1">
    <apex:column headerValue="Financial Account" id="movetoaccount">
        <apex:inputField value="{!mhItem.Financial_Account__c}" />                    
    </apex:column>
</apex:pageBlockTable>


UPDATE : with the above code, you should be able to see a table like as below. pageblocktable
Retrieve all necessary fields from Holding__c obj according to the relationships in your query (Name,Financial_Account__c,Financial_Account__r.Name,etc.) and just set the Holding__c in your constructor (I don't see a value of setting the Financial_Account__c as well here). Then you can bind them in your VF page as below.

<apex:pageBlockTable value="{!holdingList}" var="mhItem" id="pgTable1">
    <apex:column headerValue="Financial Account" id="movetoaccount">
        <apex:inputField value="{!mhItem.maho.Financial_Account__c}" />                    
    </apex:column>
    <apex:column headerValue="Test" id="movetoaccount1">
        <apex:inputField value="{!mhItem.maho.Financial_Account__r.Name}" />                    
    </apex:column>
    <apex:column headerValue="Halding Name" id="movetoaccount2">
        <apex:inputField value="{!mhItem.maho.Name}" />                    
    </apex:column>
</apex:pageBlockTable>
  • I tried your suggestion for Issue 2 and got the same error when trying to save as issue 1. – user2774325 Apr 3 '14 at 18:53
  • Confused. Note that I'm using the query result list of your controller, not the wrapper class list. And I strongly believe that you have the Lookup relationship into Financial_Account__c from Holding__c. See my update to get an idea how the table will look like (don't care about the records in there, those are just my dummy values but the relation of my two objects is exactly same as yours'). – highfive Apr 3 '14 at 19:42
  • Sorry, there's a bit more to the wrapper class than what I provided in this version of my code. I also have input fields in my wrapper class that don't exist in the query. So on the UI, the table has several object fields and also several non-object related input fields on each row. – user2774325 Apr 3 '14 at 20:53
  • I'm suspecting you still trying to bind the Financial_Account__c field of your wrapper class into your inputField. If so, no you can't do it. You have to go with the relation and bind the field, not an object. see my update to get an idea about this. – highfive Apr 4 '14 at 4:21
  • Gotcha, makes sense. So the issue with only the text displaying turned out to be due to the relationship being a Master Detail relationship. I had to turn on "Re-parenting" in order for the field to become editable. Thanks a ton for your help on this, it helped alot. – user2774325 Apr 7 '14 at 13:14

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.