You need to sign in to do that
Don't have an account?
jaanvivek
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
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.
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>
Thanks for your reply.
Could you please suggest where can i use <apex:repeat>
in my below mentioned an VF page code snippet.
Thanks for your reply.
Thanks,
jaanVivek
Hello Anand,
I tried like this.
This time I am getting error like-
Error: Unknown property 'VisualforceArrayList.name'
Could you please suggest in this case.
Thanks,
JaanVivek
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>
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:
and then have a list of innerClass type, populate it with the names.
passingData.add(new InnerClass('accountName','contactName'));
Then use this in the pageBlockTable
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.
Thanks Anand,
Here is my all code.
Below is Apex Controller Class. I ahve some doubts in it. Could you please suggets me in this case.
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
Here i want to show "AccountName" and "ContactName" in a single table in two different columns.
So please anyone help in this.