You need to sign in to do that
Don't have an account?
Sejal Pande
"Challenge Not yet complete... here's what's wrong: The Lead and Contact records with the last name 'Smith' were not found. Please add these records for this challenge." Lead and Contact record already created still getting error message
Challenge Not yet complete... here's what's wrong:
The Lead and Contact records with the last name 'Smith' were not found. Please add these records for this challenge.
I have created a Lead and Contact Record with last name 'Smith' , but I am still getting this error message on trailhead.
Below is my code:
public class ContactAndLeadSearch {
public static List<List<SObject>> searchContactsAndLeads(String str)
{
List<List<sObject>> searchContactsAndLeadsList = [FIND :str IN Name FIELDS RETURNING Contact(FirstName,LastName) ,Lead(FirstName,Lastname)];
system.debug(searchContactsAndLeadsList);
return searchContactsAndLeadsList;
}
}
Kindly assist.
Regards,
Sejal
The Lead and Contact records with the last name 'Smith' were not found. Please add these records for this challenge.
I have created a Lead and Contact Record with last name 'Smith' , but I am still getting this error message on trailhead.
Below is my code:
public class ContactAndLeadSearch {
public static List<List<SObject>> searchContactsAndLeads(String str)
{
List<List<sObject>> searchContactsAndLeadsList = [FIND :str IN Name FIELDS RETURNING Contact(FirstName,LastName) ,Lead(FirstName,Lastname)];
system.debug(searchContactsAndLeadsList);
return searchContactsAndLeadsList;
}
}
Kindly assist.
Regards,
Sejal
Use below class.
It would be helpful for you.
Thanks,
Arvind Kumar
In your code you are using In Name but you should use IN All Field like below
Execute below code in In Debug Annonymous window
Please check below post
https://developer.salesforce.com/forums/?id=906F0000000BO5rIAG
https://developer.salesforce.com/forums/?id=906F0000000BTk4IAG
Please let us know if this will help you
Contact c= new Contact();
c.LastName='Smith';
insert c;
Lead l=new Lead();
l.LastName='Smith';
l.Company='ABC';
insert l;
Than I create ContactAndLeadSearch class:
public class ContactAndLeadSearch {
Public static List<List<sObject>> searchContactsAndLeads(String searchword)
{
List<List<sObject>> searchList= [FIND :searchword IN ALL FIELDS RETURNING Lead(Name,FirstName,LastName ), Contact(FirstName,LastName )];
Lead[] searchLeadss = (Lead[])searchList[0];
Contact[] searchContacts = (Contact[])searchList[1];
System.debug('Found the following leads.');
for (Lead l : searchLeadss) {
System.debug(l.Name+', '+ l.FirstName+', '+ l.LastName);
}
System.debug('Found the following contacts.');
for (Contact c : searchContacts) {
System.debug(c.LastName + ', ' + c.FirstName);
}
system.debug(searchList);
return searchList;
}
}
I execute the code on open execute anonymous window that is below:
ContactAndLeadSearch.searchContactsAndLeads('Smith');
Finally, All things provide me to pass the module. I hope it works for you as well.