You need to sign in to do that
Don't have an account?
Sasha Ts
Method does not exist or incorrect signature: void query(String) from the type Database
Hi all,
quite easy question about Database.query method. I'm learning SF with trailhead.salesforce.com and I'm getting pretty strange error here. I'm using developer edition of SF so should be not problems with some code limits or restrictions here I hope.
https://trailhead.salesforce.com/trails/force_com_dev_beginner/modules/visualforce_fundamentals/units/visualforce_custom_controllers
Error: Method does not exist or incorrect signature: void query(String) from the type Database
quite easy question about Database.query method. I'm learning SF with trailhead.salesforce.com and I'm getting pretty strange error here. I'm using developer edition of SF so should be not problems with some code limits or restrictions here I hope.
https://trailhead.salesforce.com/trails/force_com_dev_beginner/modules/visualforce_fundamentals/units/visualforce_custom_controllers
public class ContactsListController { private String sortOrder = 'LastName'; public List<Contact> getContacts() { List<Contact> results = Database.query( 'SELECT Id, FirstName, LastName, Title, Email ' + 'FROM Contact ' + 'ORDER BY ' + sortOrder + ' ASC ' + 'LIMIT 10' ); return results; } }
Error: Method does not exist or incorrect signature: void query(String) from the type Database
The question why I missed that is quite easy to answer and it's up to SF creators team to resolve.
The auto suggest system was helped me to choose method for Database class and there was used full set of standard Database class methods. So I thought that I'm using correct standard Database class. But then the compiler used not exactly that one standard Database class but custom Database class which was auto generated(created) with an "lightningFirstApp" I've created.
So my advise to a newcomers is to check for any custom classes that could override standard ones because auto suggest system seems doesn't checks that.
All Answers
Sadly that didn't help.
Even to make my problem more clear I'll remove all not necessary things. And as you can see in the screenshot below the problem is still the same.
please try this.
public class ContactsListController {
public String sortOrder {get;set;}
public ContactsListController (){
sortOrder = 'LastName';
}
public List<Contact> getContacts() {
string sSOQL = 'SELECT Id, FirstName, LastName, Title, Email ';
sSOQL+ = ' FROM Contact ';
sSOQL+ = ' ORDER BY ' +sortOrder;
sSOQL+ = ' ASC limit 10';
List<Contact> results = Database.query(sSOQL);
system.debug('@developer-->results:'+results);
return results;
}
}
Hope to have helped!
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
let me know if any issue occured.
Regards.
The only line isn't compiling by the some reason I can't understand.
So I'm still looking for some explaination or way how could method List<sObject> query(String) from the type Database be used.
The question why I missed that is quite easy to answer and it's up to SF creators team to resolve.
The auto suggest system was helped me to choose method for Database class and there was used full set of standard Database class methods. So I thought that I'm using correct standard Database class. But then the compiler used not exactly that one standard Database class but custom Database class which was auto generated(created) with an "lightningFirstApp" I've created.
So my advise to a newcomers is to check for any custom classes that could override standard ones because auto suggest system seems doesn't checks that.
Example code
public