function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sanket supesanket supe 

Apex Basics & Database Unit 4/5

Hello...
I am facing problem in solving challange 
error says..

Challenge not yet complete... here's what's wrong: 
Executing the 'searchForContacts' method failed. Either the method does not exist, is not static, or does not return the expected contacts.
 my code is.

public class ContactSearch {
 public static List<List<SObject>> searchForContacts(String name) {
       
     List<List<SObject>> result= [FIND :name IN ALL FIELDS 
                                      RETURNING  Contact(LastName, MailingPostalCode)];
        return result;
      
}
}

please help

Thanks in Advance,
Sanket Supe
Best Answer chosen by sanket supe
Frédéric TrébuchetFrédéric Trébuchet
Hi,

This challenge is for SOQL and searchForContacts should have 2 parameters.
Here is mine:
public class ContactSearch {
	public static List<Contact> searchForContacts(String contactName, String contactPostCode) {
		List<Contact> contacts = [SELECT Name 
                                  FROM Contact 
                                  WHERE Name=:contactName 
                                  OR MailingPostalCode=:contactPostCode];
        return contacts;
    }
}
Hope this helps,
Fred

All Answers

Frédéric TrébuchetFrédéric Trébuchet
Hi,

This challenge is for SOQL and searchForContacts should have 2 parameters.
Here is mine:
public class ContactSearch {
	public static List<Contact> searchForContacts(String contactName, String contactPostCode) {
		List<Contact> contacts = [SELECT Name 
                                  FROM Contact 
                                  WHERE Name=:contactName 
                                  OR MailingPostalCode=:contactPostCode];
        return contacts;
    }
}
Hope this helps,
Fred
This was selected as the best answer
Frédéric TrébuchetFrédéric Trébuchet
Thank's, I'm now on the Smartie level!