• Baskaran Arumugam
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies

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

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

The challenge is to search for the inserted record with an inline SOSL search, using Execute Anonymous.

This is what I did using Execute Anonymous Window
 
List<List<sObject>> searchList = [FIND 'Mission Control' IN ALL FIELDS 
                                  RETURNING Contact(FirstName, LastName,
                                  Phone, Email, Description)];
Contact[] searchContacts = (Contact[])searchList[0];
System.debug('Found the following contacts:');
for (Contact c : searchContacts) {
   System.debug('"'+c.LastName + ', ' + c.FirstName+'"');
}

But still there's an error when I check the challenge.

Challenge Not yet complete... here's what's wrong: 
Could not find the contact's name in the debug log. Be sure to run a query for your record, and to write your contact's name to the debug log using the System.debug() method.
Hi,
I am not able to understand the below question correctly Please help me out. - 
Create a class that has a method accepting two strings. The method searches for contacts that have a last name matching the first string and a mailing postal code (API name: MailingPostalCode) matching the second. It gets the ID and Name of those contacts and returns them.The Apex class must be called 'ContactSearch' and be in the public scope.
The Apex class must have a public static method called 'searchForContacts'.
The 'searchForContacts' method must accept two incoming strings as parameters, find any contact that has a last name matching the first, and mailing postal code matching the second string. The method should return a list of Contact records with at least the ID and Name fields.
The return type for 'searchForContacts' must be 'List<Contact>'.