function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
YashhYashh 

Error: Compile Error: Found punctuation symbol or operator '%' that isn't valid in Apex. at line 6 column 87

Error: Compile Error: Found punctuation symbol or operator '%' that isn't valid in Apex. at line 6 column 87

Apex Code
public class searchBox {
    public list <Account> acc {get;set;}
    public String searchKey {get;set;}
    public searchBox( ) {} 
    public void search(){
        string searchquery='select Name,id from account where name like \ +searchKey+'%\'';
        acc= Database.query(searchquery);
    }
}


This My VF CODE
<apex:page Controller="searchBox">
    <apex:form >
        <apex:inputText value="{!searchKey}" label="Input"/><br/>
        <apex:commandButton value="Enter" action="{!search}"/>
        <apex:pageBlock title="Searched Accounts are:-">
            <apex:pageBlockTable value="{!acc}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Best Answer chosen by Yashh
CharuDuttCharuDutt
Hii Yash
Try Below Code
public class searchBox {
    public list <Account> acc {get;set;}
    public String searchKey {get;set;}
    public searchBox( ) {} 
    public void search(){
        string searchquery='select Name,id from account where name like '+searchKey+'%' ;
        acc.add(Database.query(searchquery));
    }
}
Please Mark It As Best Answer If It Helps
Thank You!

 

All Answers

CharuDuttCharuDutt
Hii Yash
Try Below Code
public class searchBox {
    public list <Account> acc {get;set;}
    public String searchKey {get;set;}
    public searchBox( ) {} 
    public void search(){
        string searchquery='select Name,id from account where name like '+searchKey+'%' ;
        acc.add(Database.query(searchquery));
    }
}
Please Mark It As Best Answer If It Helps
Thank You!

 
This was selected as the best answer
YashhYashh
Thanks CharuDutt