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
Baskaran ArumugamBaskaran Arumugam 

Create an Apex class that returns contacts based on incoming parameters in trailhead

I have a write a below code for achieve the above in trailhead, but it shows below error : Illegal assignment from List<Contact> to List<contact>

Code: 

public class ContactSearch {
public static list<contact> searchForContacts(string lastname,string MailingPostalCode)
    { 
        list<contact> ContactList=[select id,name,lastname,mailingpostalcode from contact where lastname=:lastname and mailingpostalcode=:MailingPostalcode];
        return contactlist;
    }
}

Rounak SharmaRounak Sharma
hi baskaran,

you need to check like
public class ContactSearch {
    public static List<Contact> searchForContacts(string lastname,string MailingPostalCode){
        list<contact>ContactList= [select id,name,lastname,mailingpostalcode from contact where lastname=:lastname and mailingpostalcode=:MailingPostalcode];
        return ContactList;
    }
}

Please let me know if it solves your problem.
thanks
Ajay K DubediAjay K Dubedi
Hi Baskaran,

Your Code works fine in my org.
 
public class ContactSearch 
{
    public static list<contact> searchForContacts(string lastname,string MailingPostalCode)
    { 
        list<contact> ContactList=[select id,name,lastname,mailingpostalcode from contact where lastname=:lastname and mailingpostalcode=:MailingPostalcode];
        return contactlist;
    }
}

* Please make Sure that you give the correct details during execution time.

 eg. ContactSearch.searchForContacts('hello','12345');
     I have Created a Contact named as 'hello' and its mailingpostalcode as '12345'.
     and the code return the list containg that contact

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
Baskaran ArumugamBaskaran Arumugam
Again got the same error..