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
Hima Bindu MokaHima Bindu Moka 

Hi,please help me with the Apex code which I'm trying get Contacts fields by passing parameters in a method in Trailhead

Hi,please help me with the Apex code which I'm trying get Contacts fields by passing parameters in a method in Trailhead

this is error
Best Answer chosen by Hima Bindu Moka
Amit Chaudhary 8Amit Chaudhary 8
Hi  Hima Bindu Moka,

Your code look good to me, Just save  your code in APEX classes.
public class ContactSearch
{
    public static List<Contact> searchForContacts(string s1, string s2)
	{
        List<Contact> conList = [Select id, name,firstName,LastName from Contact where lastname = :s1 and mailingpostalcode =:s2 ];
        return conList;
    }
}

Then to test your code you can try below code in developer console
 
List<Contact> lstCont = ContactSearch.searchForContacts('TestName','123');
Please let us know if this will help you.

Thanks
Amit Chaudhary

 

All Answers

William TranWilliam Tran
Your codes should look like this:
 
public class ContactSearch{

    public static List<contact> searchForContacts(string a, string b){
        List<contact> contactlist = [Select id, name from contact where lastname = :a and mailingpostalcode =:b];
        return contactlist;
    }
}

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you. 

This will help keep the forum clean and help future users determine what answers are useful and what answer was the best in resolving the user's issue. 

Thanks
Amit Chaudhary 8Amit Chaudhary 8
Hi  Hima Bindu Moka,

Your code look good to me, Just save  your code in APEX classes.
public class ContactSearch
{
    public static List<Contact> searchForContacts(string s1, string s2)
	{
        List<Contact> conList = [Select id, name,firstName,LastName from Contact where lastname = :s1 and mailingpostalcode =:s2 ];
        return conList;
    }
}

Then to test your code you can try below code in developer console
 
List<Contact> lstCont = ContactSearch.searchForContacts('TestName','123');
Please let us know if this will help you.

Thanks
Amit Chaudhary

 
This was selected as the best answer
Hima Bindu MokaHima Bindu Moka
Thanks,While testing the code, I forgot to put single quotes in the method while passing the strings.