You need to sign in to do that
Don't have an account?

Error in trailhead challenge Apex Basics & Database(Write SOQL Queries): Executing the 'searchForContacts' method failed. Either the method does not exist, is not static, or does not return the expected contacts.
Error:Executing the 'searchForContacts' method failed. Either the method does not exist, is not static, or does not return the expected contacts.
Code:
public class ContactSearch {
public static List<Contact> searchForContacts(String lastName, String mailingPostalCode){
List<Contact> contactList=null;
contactList=[SELECT Id,Name from Contact where (Last_Name__c=:lastName OR MailingPostalCode=:mailingPostalCode)];
return contactList;
}
}
Code:
public class ContactSearch {
public static List<Contact> searchForContacts(String lastName, String mailingPostalCode){
List<Contact> contactList=null;
contactList=[SELECT Id,Name from Contact where (Last_Name__c=:lastName OR MailingPostalCode=:mailingPostalCode)];
return contactList;
}
}
Try this, it will work .
Hope, it will help you,
Regards Suraj
All Answers
Try this, it will work .
Hope, it will help you,
Regards Suraj
I was returning a table (contact[]) and not a list.
public class ContactSearch {
public static list<Contact> searchForContacts(String s1,String s2){
Contact[] con=[Select ID, Name from Contact where LastName=:s1 and MailingPostalCode=:s2];
return con;
}
}
public static List<List<sObject>> searchContactsAndLeads(string Cname){
List<List<sObject>> searchList=[FIND :Cname IN ALL FIELDS RETURNING
Lead(FirstName, LastName), Contact(FirstName,LastName)];
return searchList;
}
}