You need to sign in to do that
Don't have an account?
could any one please suggest some solution to this problem
Error:Could not resolve the entity from <apex:inputField> value binding '{!Product.Name}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.
could any one please suggest some solution to this problem
VF code:
<apex:page controller="ProductSearchController" sidebar="false">
<apex:form >
<apex:pageMessages id="errors" />
<apex:pageBlock title="Find Me A Product!" mode="edit">
<table width="100%" border="0">
<tr>
<td width="200" valign="top">
<apex:pageBlock title="Parameters" mode="edit" id="criteria">
<script type="text/javascript">
function doSearch() {
searchServer(
document.getElementById("Name").value,
document.getElementById("Code").value,
);
}
</script>
<apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
<apex:param name="Name" value="" />
<apex:param name="Code" value="" />
</apex:actionFunction>
<table cellpadding="2" cellspacing="2">
<tr>
<td style="font-weight:bold;">Name<br/>
<input type="text" id="Name" onkeyup="doSearch();"/>
</td>
</tr>
<tr>
<td style="font-weight:bold;">Code<br/>
<input type="text" id="Code" onkeyup="doSearch();"/>
</td>
</tr>
</table>
</apex:pageBlock>
</td>
<td valign="top">
<apex:pageBlock mode="edit" id="results">
<apex:pageBlockTable value="{!Product2}" var="Product">
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Name" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Product.Name" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField/> value="{!Product.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Code" action="{!toggleSort}" rerender="results,debug">
<apex:param name="sortField" value="Product.Productcode" assignTo="{!sortField}"/>
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!Product.ProductCode}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</td>
</tr>
</table>
<apex:pageBlock title="Debug - SOQL" id="debug">
<apex:outputText value="{!debugSoql}" />
</apex:pageBlock>
</apex:pageBlock>
</apex:form>
</apex:page>
ProductSearchController code:
public with sharing class ProductSearchController
{
public String getProduct() {
return null;
}
public String Product2 { get; set; }
// the soql without the order and limit
private String soql {get;set;}
// the collection of contacts to display
public List<Product2> Products {get;set;}
// the current sort direction. defaults to asc
public String sortDir
{
get
{
if (sortDir == null)
{
sortDir = 'asc';
}
return sortDir; }
set;
}
// the current field to sort by. defaults to last name
public String sortField
{
get
{
if (sortField == null)
{
sortField = 'Name';
}
return sortField;
}
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
set;
}
// init the controller and display some sample data when the page loads
public ProductSearchController() {
soql = 'select name,productcode from Product2 where name != null';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort()
{
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery()
{
try {
Products = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String Name = Apexpages.currentPage().getParameters().get('Name');
String Code = Apexpages.currentPage().getParameters().get('Code');
soql = 'select name,productcode from product2 where name != null';
if (!Name.equals(''))
soql += ' and product2.name LIKE \''+String.escapeSingleQuotes(Name)+'%\'';
if (!code.equals(''))
soql += ' and product2.productcode LIKE \''+String.escapeSingleQuotes(Code)+'%\'';
// run the query again
runQuery();
return null;
}
}
How do you set up your sample data? If you set it up in the constructor or getter you should be fine.
Also, check that you have bound the values correctly in the Visualforce components.
All Answers
Due to this property:
product is defined as a string, so when you try to access a field called Name, that will fail as the String primitive doesn't have fields.
I can't tell you the exact code, as I haven't been through all of your code to understand and correct it.
Bottom line is you are trying to use a string as a product - that suggests to me that you should either change the string to a product, or be using another property that really is a product.
How do you set up your sample data? If you set it up in the constructor or getter you should be fine.
Also, check that you have bound the values correctly in the Visualforce components.