You need to sign in to do that
Don't have an account?

Trailhead Challenge: Write an Inline SOSL Search to Return Database Values
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
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.
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.
Try this : It worked for me.
Thanks,
Dhanya
All Answers
Please try with below class. NOTE: If you want to search with same keyword in multiple fields then don't add where you can try IN ALL FIELDS.
Execute below code in In Debug Annonymous window. Please check below post
- https://developer.salesforce.com/forums/?id=906F0000000BO5rIAG
Please let us know if this will help you.Best Regards,
Nagendra.
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.
Try this : It worked for me.
Thanks,
Dhanya
Yes, try Dhnaya's code. it works.
Thanks
Ashok
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.
If you don't have that one extra space the test will fail. No need to login into different org / playground.
//Contact thisContact = new Contact( Firstname='Brian', Lastname='Dent', Phone='(619)852-4569', Department='Mission Control', Title='Mission Specialist - Neptune', Email='briandent@trailhead.com');
//insert thisContact;
List<List<SObject>> c=[FIND 'Mission Control'IN ALL FIELDS RETURNING Contact(FirstName, LastName)];
Contact [] contacts = ((List<Contact>)c[0]);
System.debug(contacts[0].LastName+','+contacts[0].FirstName);
Try to login into another org and then check the Challenge
Just tried today..It worked out
List<List<sObject>> sl = [-------]
insert and run the code that adds a new contact, which we will then look for.
step 2.
after the contact is added to our database, we make a request for a posik. Copy this code and run it.
step 3.
We check the execution of the task, everything should work.
Then Clear Whole Window And Execute Only This
List<List<sObject>> con = [FIND 'Mission Control' IN ALL FIELDS RETURNING Contact(FirstName,LastName)];
Contact[] conn = (Contact[])con[0];
for(Contact co:conn){
system.debug(co.LastName+', '+co.FirstName);
//Don't forget to put a space after " , "
}
2. debug > open execute annonymous window
3. enter the code-snippet below
Contact thisContact = new Contact( Firstname='Brian', Lastname='Dent', Phone='(619)852-4569', Department='Mission Control', Title='Mission Specialist - Neptune', Email='briandent@trailhead.com');
insert thisContact;
//System.debug('Found the following contact');
System.debug(thisContact.Lastname + ', ' + thisContact.Firstname);
4. execute
5. can checkmark 'Debug only' checkbox to see the return.
I completed the challenge with below code.
List<List<sObject>> searchList = [FIND 'Mission Control' IN ALL FIELDS RETURNING Contact(FirstName, LastName, Phone, Email, Description)]; Contact[] searchContacts = (Contact[])searchList[0]; System.debug(searchContacts[0].LastName + ', ' + searchContacts[0].FirstName);
Try this
First, you have to Select Debug | Open Execute Anonymous Window.
Copy this code & Execute -
Contact thisContact = new Contact( Firstname='Brian', Lastname='Dent', Phone='(619)852-4569', Department='Mission Control', Title='Mission Specialist - Neptune', Email='briandent@trailhead.com');
insert thisContact;
After the first step does this:
Select Debug | Open Execute Anonymous Window.
Copy this code & Execute -
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);
}
This worked for me.
For me not working..
I got below error:
Incompatible types since an instance of List<SObject> is never an instance of List<contact>
https://mcafeeactivateretailcardkey.yahoosites.com
https://sklep.grupamagnum.eu
https://testdepurete.info