Title: Visualforce sObject error
Tags: apex;visualforce
Question: I have two custom objects, Package__c and Product__c, I'm trying to create a form that will take input for fields of both objects on a single visualforce page and Save the data accordingly. Here is my Visualforce page -
<apex:page controller=&quot;RedirectedController&quot;&gt;
<apex:form &gt;
<apex:pageBlock &gt;

<apex:pageBlockSection columns=&quot;2&quot;&gt;

<apex:inputField label=&quot;Name&quot; value=&quot;{!objectpkg.Name}&quot;/&gt;
<apex:inputField label=&quot;Account&quot; value=&quot;{!objectpkg.Account__c}&quot;/&gt;
<apex:inputField label=&quot;Type&quot; value=&quot;{!objectpkg.Package_Type__c}&quot;/&gt;
<apex:inputField label=&quot;Cost Of Goods&quot; value=&quot;{!objectpkg.Cost_of_Goods_Sold__c}&quot;/&gt;
<apex:inputField label=&quot;Quantity Of Goods&quot; value=&quot;{!objectpkg.Quantity_of_Goods_Sold__c}&quot;/&gt;
<apex:inputField label=&quot;Ready to Ship&quot; value=&quot;{!objectpkg.Ready_to_Ship__c}&quot;/&gt;

</apex:pageBlockSection&gt;

<apex:pageBlockButtons &gt;
<apex:commandButton action=&quot;{!saveAll}&quot; value=&quot;Save&quot;/&gt;
<apex:commandButton value=&quot;Cancel&quot;/&gt;
</apex:pageBlockButtons&gt;
</apex:pageBlock&gt;
<apex:inputField label=&quot;Family&quot; value=&quot;{!objectprod.Product_Family__c}&quot;/&gt;
</apex:form&gt;
</apex:page&gt;
Apex Code
public with sharing class RedirectedController
public List<Package__c&gt; objectpkg {get; set;}
public List<Product__c&gt; objectprod {get; set;}
public Package__c pkg {get; set;}
public Product__c prod {get; set;}
public RedirectedController()
List<Package__c&gt; objectpkg = new List<Package__c&gt;();
List<Product__c&gt; objectprod = new List<Product__c&gt;();
objectpkg = [SELECT Account__c, Cost_of_Goods_Sold__c, Name, Package_Type__c, Quantity_of_Goods_Sold__c, Ready_to_Ship__c FROM Package__c];
objectprod =[SELECT Product_Family__c From Product__c];
public void saveAll()
insert objectpkg;
insert objectprod;
I get the error as &quot;Could not resolve the entity from apex:inputField value binding '{!objectpkg.Name}'.  apex:inputField can only be used with SObjects, or objects that are Visualforce field component resolvable.&quot;
What am I doing wrong?

Here is the accepted answer: Presumably, you are expecting only a single Product__c and Package__c for the VF form
so, use singleton properties in the controller and resolve the queries to a single record
public with sharing class RedirectedController
public Package__c objectpkg {get; set;}
public Product__c objectprod {get; set;}
public Package__c pkg {get; set;}
public Product__c prod {get; set;}
public RedirectedController()
objectpkg = [SELECT Account__c, Cost_of_Goods_Sold__c, Name, Package_Type__c, Quantity_of_Goods_Sold__c, Ready_to_Ship__c
FROM Package__c][0];
objectprod =[SELECT Product_Family__c From Product__c][0];
public void saveAll()
insert objectpkg;
insert objectprod;
It is not clear from your VF form where the values of variables Product__c and Package__c come from -- these are sobjects and have to be queried for from some ID field made available to the controller in a URL parameter

Here is another answer: objectprod is a List<Product__c&gt; so you cannot get the field from a list.
You need to iterate and then use it.
Comment for this answer: Could you post the Code ? I'm new to Salesforce so it would be helpful
Comment for this answer: You can google it, tons of example out there. Google it and you will learn faster. For eg: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_repeat.htm
Comment for this answer: I tried `   ` and so on, now I'm not getting any errors but the inputfields are not showing up on the page
Comment for this answer: `Account__c` is a Id so it will act as a lookup. but it will show in the UI. There might be some error in your code.

{'source': 'StackExchangeDataset', 'subset': 'salesforce.stackexchange.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:12/04/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<apex><visualforce>', 'Title': 'Visualforce sObject error', 'ViewCount': 51, 'id': 328087, 'user_AboutMe': '', 'user_AccountId': 8533357.0, 'user_DisplayName': 'An Amateur', 'user_Reputation': 9.0, 'user_Views': 7.0, 'user_id': 90748.0}}