+ Start a Discussion
jaanvivekjaanvivek 

Error: Could not resolve the entity from <apex:outputField> can only be used with SObject fields.

Hello All,

 

I need youe help.

 

I am writing an VF page which does need to diplay " Account and Contact "   Name in seperate columns in the same pageBlockTable.

 

I am geeting error 

 

Error: Could not resolve the entity from <apex:outputField> value binding '{!showData.catchAcc.name}'. <apex:outputField> can only be used with SObject fields.

 

 

Here is the below code snippet.

 

<apex:page controller="AllData" sidebar="false" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!passingData}" var="showData">
<apex:column headerValue="AccountName">
<apex:outputField value="{!showData.catchAcc.name}"/>
</apex:column>
<apex:column headerValue="ContactName">
<apex:outputField value="{!showData.catchCon.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Apex Controller-

 

public class AllData
{
    public List<innerClass> passingData { get; set; }
    public List<Account> allAcc {get;set;}
    public List<Contact> allCon{get;set;}
    
    
    public AllData()
    {
       passingData=new List<innerClass>();
       allAcc=[select id,name from Account limit 10];
       allCon=[select id,name from Contact limit 10];
       innerClass allAddData=new innerClass(allAcc ,allCon);
       passingData.add(allAddData);
    
    
    }
    
    public class innerClass
    {
         
        public List<Account> catchAcc {get;set;}
        public List<Contact> catchCon {get;set;}
        public innerClass(list<Account> gettingaccs,list<Contact> gettingcons)
        {    
            catchAcc = gettingaccs;
            catchCon = gettingcons;
        }
    
    }
    
    
    
    
    
    
    
    
}

 

 

Thanks for your all valuable suggestions.

 

it will help me to improve the way of coding .

 

 

Thanks,

JaanVivek

 

vishal@forcevishal@force

Hello,

 

<apex:outputField> will only accept SObject fields, it means it will accept any field that is present on an SObject.

 

Example : Account.Name or Opportunity.Amount (this are fields on SObjects).

 

In your case, you are having a wrapper object that is binded to the outputField and not an Sobject binding. So it gives you the error.

 

You can use an <apex:outputText> instead of <apex:outputField> in such a case.

neophyteneophyte

The issue in your code is that you are not referring to a single account when you use:

<apex:outputField value="{!showData.catchAcc.name}"/>

 

As described in your inner class catchAcc is not an account, but a list of accounts. The same error with using catchCon also.

 

You should iterate through this list of accounts or contacts to display the same. Example:

 

<apex:repeat value="{!showData.catchAcc.name}" var="acct">

 <apex:outputField value="{!acct.name}"/>

</apex:repeat>

 

 

jaanvivekjaanvivek

Thanks for your reply.

 

Could you please suggest where can i use <apex:repeat>

 

in my below mentioned an VF page code snippet.

 

<apex:page controller="AllData" sidebar="false" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!passingData}" var="showData">

<apex:column headerValue="AccountName">
<apex:outputField value="{!showData.catchAcc.name}"/>
</apex:column>
<apex:column headerValue="ContactName">
<apex:outputField value="{!showData.catchCon.name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 Thanks for your reply.

 

 

Thanks,

jaanVivek

jaanvivekjaanvivek

Hello Anand,

 

I tried like this.

 

<apex:page controller="AllData" sidebar="false" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!passingData}" var="showData">
<apex:column headerValue="AccountName">
<apex:repeat value="{!showData.catchAcc.name}" var="acct">
<apex:outputField value="{!acct.name}"/>
</apex:repeat>
</apex:column>
<apex:column headerValue="ContactName">
<apex:repeat value="{!showData.catchCon.name}" var="cont">
<apex:outputField value="{!cont.name}"/>
</apex:repeat>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

  This time I am getting error like-

 


Error: Unknown property 'VisualforceArrayList.name'

 

Could you please suggest in this case.

 

Thanks,

JaanVivek

neophyteneophyte

My dear friend, I'm sorry there was an error in what I posted.

 

showData.catchAcc is the list. So the correct code should be:

 

<apex:repeat value="{!showData.catchAcc}" var="acct">

 <apex:outputField value="{!acct.name}"/>

</apex:repeat>

neophyteneophyte

But then again, I don't think the table will come out as you expect it. It will come as a single row table, since the data source for the page block table is a single element list.

 

If you want the accounts and contacts to be shown in a table as 10 different rows (each row containing one contact nameand one account name). Then your inner class should be like this:

 

public class innerClass
    {
         
        public String accountName {get;set;}
        public String contactName {get;set;}
        public innerClass(String aName, String cName)
        {    
            accountName = aName;
            contactName = cName;
        }
    
    }

 and then have a list of innerClass type, populate it with the names.

 

passingData=new List<innerClass>();

 

passingData.add(new InnerClass('accountName','contactName'));

 

Then use this in the pageBlockTable

 

<apex:page controller="AllData" sidebar="false" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!passingData}" var="showData">
<apex:column headerValue="AccountName">
<apex:outputField value="{!showData.accountName}"/>
</apex:column>
<apex:column headerValue="ContactName">
<apex:outputField value="{!showData.contactName}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
neophyteneophyte

 

 

<apex:page controller="AllData" sidebar="false" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!passingData}" var="showData">
<apex:column headerValue="AccountName">
<apex:outputText value="{!showData.accountName}"/>
</apex:column>
<apex:column headerValue="ContactName">
<apex:outputText value="{!showData.contactName}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

One error in the above case: use <apex:outputText in this case as it is not a field but a String type variable which I am trying to render.

jaanvivekjaanvivek

Thanks Anand,

 

Here is my all code.

 

<apex:page controller="AllData" sidebar="false" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!passingData}" var="showData">
<apex:column headerValue="AccountName">
<apex:outputText value="{!showData.accountName}"/>
</apex:column>
<apex:column headerValue="ContactName">
<apex:outputText value="{!showData.contactName}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

Below is Apex Controller Class. I ahve some doubts in it. Could you please suggets me in this case.

 

public class AllData
{
    public List<innerClass> passingData { get; set; }
    public List<Account> allAcc {get;set;}
    public List<Contact> allCon{get;set;}
    
    
    public AllData()
    {
       passingData=new List<innerClass>();
       allAcc=[select id,name from Account limit 10];
       allCon=[select id,name from Contact limit 10];
       innerClass allAddData=new innerClass(allAcc ,allCon);
       passingData.add(allAddData);
       passingData.add(new InnerClass('accountName','contactName'));
    
    
    }
    
    public class innerClass
    {
         
        public String accountName{get;set;}
        public String contactName{get;set;}
        public innerClass(String aname,String cName)
        {    
            accountName= aName;
            contactName= cName;
        }
    
    }
    
    
    
    
    
    
    
    
}

   I am getting error like-


Error: AllData Compile Error: Constructor not defined: [AllData.innerClass].<Constructor>(LIST<Account>, LIST<Contact>) at line 13 column 30

 

 

I am new to this environment. So please help me to do it correctly.

 

Thanks,

JaanVivek

jaanvivekjaanvivek

Here i want to show  "AccountName" and "ContactName" in a single table in two different columns.

 

So please anyone help in this.