You need to sign in to do that
Don't have an account?
Aron Schor [Dev]
Help with VF search page ("line breaks not allowed" error) and other questions
Hi, I can use the code here, but I want to tweak it to work for Products. I am hoping with some basic changes it can work. I am a bit new to programming. I posted on the site asking for help but got no reply so hoping someone here can help.
http://nirmalchristopher.blogspot.com/2013/12/search-page-in-visualforce-simplified.html
I tried changing the query to be
string searchquery='select Name, ProductCode, Description, Notes__C from Product2 where (Name like \'%'+searchstring+'%\' OR ProductCode like \'%'+searchstring+'%\' OR Description like \'%'+searchstring+'%\' OR Notes__C like \'%'+searchstring+'%\');
and it says
Error: Compile Error: line breaks not allowed in string literals at line 7 column -1
How do I fix?
Also, I assume to modify the page I would have to change
1. <apex:page standardController="account" extensions="accsearchcontroller">
"account" to "Product2"
2. and also change add output.
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.ProductCode}</apex:outputlink>
etc
Anything else?
Thanks!
http://nirmalchristopher.blogspot.com/2013/12/search-page-in-visualforce-simplified.html
I tried changing the query to be
string searchquery='select Name, ProductCode, Description, Notes__C from Product2 where (Name like \'%'+searchstring+'%\' OR ProductCode like \'%'+searchstring+'%\' OR Description like \'%'+searchstring+'%\' OR Notes__C like \'%'+searchstring+'%\');
and it says
Error: Compile Error: line breaks not allowed in string literals at line 7 column -1
How do I fix?
Also, I assume to modify the page I would have to change
1. <apex:page standardController="account" extensions="accsearchcontroller">
"account" to "Product2"
2. and also change add output.
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.ProductCode}</apex:outputlink>
etc
Anything else?
Thanks!
All Answers
You don't need to make any other change in the code.
The Apex class seems to work!
How about the page? I guess the issue is line one.
It says:
Error: Unknown property 'Product2StandardController.pro'
I guessed and tried CustomController.
Error: Unsupported attribute customcontroller in <apex:page> in prodsearch at line 1 column 74
Just controller says:
Error: Apex class 'Product2' does not exist
<apex:page standardController="Product2" extensions="prodsearchcontroller">
<apex:form >
<apex:inputText value="{!searchstring}" label="Input"/>
<apex:commandButton value="Search records" action="{!search}"/>
<apex:commandButton value="Clear records" action="{!search}"/>
<apex:pageBlock title="Search Result">
<apex:pageblockTable value="{!pro}" var="a">
<apex:column >
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.ProductCode}</apex:outputlink>
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Description}</apex:outputlink>
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Notes__C}</apex:outputlink>
</apex:column>
<apex:column value="{!a.id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Notes regarding the object, if it helps.
label: Product
labelPlural: Products
name: Product2
Here is the page code and what I see. I want columns for the different values and I don't need the Product id part.
<apex:page standardController="Product2" extensions="prodsearchcontroller">
<apex:form >
<apex:inputText value="{!searchstring}" label="Input"/>
<apex:commandButton value="Search records" action="{!search}"/>
<apex:commandButton value="Clear records" action="{!search}"/>
<apex:pageBlock title="Search Result">
<apex:pageblockTable value="{!prod}" var="a">
<apex:column >
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.ProductCode}</apex:outputlink>
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Description}</apex:outputlink>
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Notes__c}</apex:outputlink>
</apex:column>
<apex:column value="{!a.id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
______________
Apex Class
public with sharing class prodsearchcontroller {
public list <Product2> Prod {get;set;}
public string searchstring {get;set;}
public prodsearchcontroller(ApexPages.StandardController controller) {
}
public void search(){
string searchquery='select Name, ProductCode, Description, Notes__C from Product2 where Name like \'%'+searchstring+'%\' OR ProductCode like \'%'+searchstring+'%\' OR Description like \'%'+searchstring+'%\' OR Notes__C like \'%'+searchstring+'%\'';
Prod= Database.query(searchquery);
}
public void clear(){
prod.clear();
}
}
_______________
I tried using this code but it says (just a guess on my part. Not sure how to fix)
Error: <apex:column> must be the direct child of either <apex:dataTable> or <apex:pageBlockTable>
<apex:page standardController="Product2" extensions="prodsearchcontroller">
<apex:form >
<apex:inputText value="{!searchstring}" label="Input"/>
<apex:commandButton value="Search records" action="{!search}"/>
<apex:commandButton value="Clear records" action="{!search}"/>
<apex:pageBlock title="Search Result">
<apex:pageblockTable value="{!prod}" var="a">
<apex:column >
<apex:column value="{!a.Name}"/>
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Name}</apex:outputlink>
<apex:column >
<apex:column value="{!a.ProductCode}"/>
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.ProductCode}</apex:outputlink>
<apex:column >
<apex:column value="{!a.Description}"/>
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Description}</apex:outputlink>
<apex:column >
<apex:column value="{!a.Notes__C}"/>
<apex:outputlink value="https://ap1.salesforce.com/{!a.id}">{!a.Notes__c}</apex:outputlink>
</apex:column>
</apex:column>
</apex:column>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks