I am doing the challenge in the 'Write SOQL Queries Unit' module and I eventually get this message 'Executing the 'searchForContacts' method failed. Either the method does not exist, is not static, or does not return the expected contacts.' I am not sure how to debug the code to figure out what is wrong. How can I debug it, or what might be going wrong in my code below?
public class ContactSearch {
public static List<Contact> searchForContacts(String lName, String pCode){
String contactSearch = 'SELECT Id, Name FROM Contact WHERE Name = \'' + lName + '\' AND MailingPostalCode = \'' + pCode + '\'';
List<Contact> output = Database.query(contactSearch);
return output;
}
}
Hi William,
Try this code :
public class ContactSearch
{
public static List<Contact> searchForContacts(String Str1, String Str2)
{
List<Contact> ContactList = [select ID,Name from Contact where LastName = :Str1 and MailingPostalCode = :Str2];
return ContactList;
}
}
Hope this will resolve your query,
Thanks
Piyush