+ Start a Discussion
NandhuNandhu 

Correct my trailhead challeneg

public class ContactSearch {

    public Static List<Contact> getSearchForContacts(String lastName,String mailingPostalCode)
    {
        List<Contact> myobj = [SELECT ID,LastName,MailingPostalCode FROM Contact WHERE LastName=:lastName AND MailingPostalCode=:mailingPostalCode];
       System.debug('.....:' +myobj);
        return myobj;
}
}

Sql editor
:SELECT ID, Name, MailingPostalCode FROM Contact WHERE LastName ='Davis'
Anonymous debug:
ContactSearch.getSearchForContacts('Young','66045');

 
Best Answer chosen by Nandhu
Ajay K DubediAjay K Dubedi
Hi Nandhini,

I have gone through your issue.
Your logic is correct. There are only two minor mistakes.
First, your method name should be SearchForContacts instead of getSearchForContacts. Please remove 'get' from the name. 
Trailhead challenges can only be completed if your class and method names match the names defined in the challenge.
Second, in your query, you have to fetch Name not LastName as the challenge requires the last name. 
Salesforce generates Name automatically by combining the first name and last name. 


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com

All Answers

Foram Rana RForam Rana R
Can you please share when you got the error ?
 
Foram Rana RForam Rana R
Please Use Below 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;
    }
}
 I hope this helps you.
If this helps kindly mark it as solved so that it may help others in future.

Thanks & Regards,
Foram Rana
NandhuNandhu
my logic is correct and got the output but still trailhead said that there is no static method and doesn't return any value
NandhuNandhu
What is about my program
Foram Rana RForam Rana R
It's correct.
 
Ajay K DubediAjay K Dubedi
Hi Nandhini,

I have gone through your issue.
Your logic is correct. There are only two minor mistakes.
First, your method name should be SearchForContacts instead of getSearchForContacts. Please remove 'get' from the name. 
Trailhead challenges can only be completed if your class and method names match the names defined in the challenge.
Second, in your query, you have to fetch Name not LastName as the challenge requires the last name. 
Salesforce generates Name automatically by combining the first name and last name. 


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
This was selected as the best answer
Deepali KulshresthaDeepali Kulshrestha
Hi Nandhini,

I have gone through your problem. Sometimes these things happen in trailhead.

Please try the code given below in my trailhead I done the same:-
public class ContactSearch
{
    public static List<Contact> searchForContacts(String St1, String St2)
    {
        List<Contact> ContctList = [select ID,Name from Contact where LastName = :St1 and MailingPostalCode = :St2];
        return ContctList;
    }
}


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com