+ Start a Discussion
Ashutosh SalgaonkarAshutosh Salgaonkar 

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;
    }
}
 
Best Answer chosen by Ashutosh Salgaonkar
Suraj TripathiSuraj Tripathi
Hi Ashutosh,

Try this, it will work .
 
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, it will help you,
Regards Suraj
 

All Answers

Suraj TripathiSuraj Tripathi
Hi Ashutosh,

Try this, it will work .
 
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, it will help you,
Regards Suraj
 
This was selected as the best answer
Falk Wegener 12Falk Wegener 12
Nice helped me too.
I was returning a table  (contact[]) and not a list.
Apar JaggiApar Jaggi
// Try this

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;
    }