You need to sign in to do that
Don't have an account?
Raksha Tiwari
System.QueryException: unexpected token: 10
This is my controller :
public class ContactsListController{
private string sortOrder = 'LastName';
public List<Contact> getContacts(){
string soqlQuery = 'SELECT Id, FirstName, LastName, Title, Email'+ 'from Contacts'+ 'OrderBy' + sortOrder
+ 'ASC' + 'LIMIT 10' ;
List<Contact> results = Database.query(soqlQuery);
return results;
}
}
And this is my visualforce page :
<apex:page controller="ContactsListController" >
<apex:form >
<apex:pageBlock title="Contacts List" id="Contacts_list">
<apex:pageBlockTable value="{!Contacts}" var="ct">
<apex:column value="{!ct.FirstName}"/>
<apex:column value="{!ct.LastName}"/>
<apex:column value="{!ct.Title}"/>
<apex:column value="{!ct.Email}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
I'm getting an error "System.QueryException: unexpected token: 10 " while saving the above vf page. Please help.
public class ContactsListController{
private string sortOrder = 'LastName';
public List<Contact> getContacts(){
string soqlQuery = 'SELECT Id, FirstName, LastName, Title, Email'+ 'from Contacts'+ 'OrderBy' + sortOrder
+ 'ASC' + 'LIMIT 10' ;
List<Contact> results = Database.query(soqlQuery);
return results;
}
}
And this is my visualforce page :
<apex:page controller="ContactsListController" >
<apex:form >
<apex:pageBlock title="Contacts List" id="Contacts_list">
<apex:pageBlockTable value="{!Contacts}" var="ct">
<apex:column value="{!ct.FirstName}"/>
<apex:column value="{!ct.LastName}"/>
<apex:column value="{!ct.Title}"/>
<apex:column value="{!ct.Email}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
I'm getting an error "System.QueryException: unexpected token: 10 " while saving the above vf page. Please help.
Note : Please mark this answer as Best Answer if it helps you in giving a surface understanding about your problem. Doing this, will help the community to directly refer to this answer
Thank you
Blearn-Sai
All Answers
// private string sortOrder = 'LastName';
public List<Contact> getContacts(){
/*string soqlQuery = 'SELECT Id, FirstName, LastName, Title, Email'+ 'from Contacts'+ 'OrderBy' + sortOrder
+ 'ASC' + 'LIMIT 10' ;*/
String soqlQuery= 'select id,FirstName,LastName,Title,Email from Contacts ORDERBY LastName ASC LIMIT 10';
List<Contact> results = Database.query(soqlQuery);
return results;
}
}
try this may help u
Note : Please mark this answer as Best Answer if it helps you in giving a surface understanding about your problem. Doing this, will help the community to directly refer to this answer
Thank you
Blearn-Sai
SELECT Id, FirstName, LastName, Title, Emailfrom ContactsOrderByLastNameASCLIMIT 10
If you observe this carefully you can see spaces are missing. Take care of space after each word.
'OrderBy' should be 'Order By'.
I believe you are trying to query standard object Contact. Change 'Contacts' to 'Contact'
Hope this helps :)
Change your query:
with the following and it will work properly.
Your code was "almost" right. :)