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
William Rohrbach 1William Rohrbach 1 

Execute SOQL and SOSL Queries challenge error

I am attempting to complete the Execute SOQL and SOSL Queries in the Developer Console Basics module and the challenge is creating logs that have nothing to do with the SOSL inline query that is requested. I have executed the following code in the Execute anonymous window and the challenge still does not show as completed.
 
List<List<sObject>> searchList = [FIND 'Mission Control' IN ALL FIELDS 
                                  RETURNING Contact(FirstName, LastName,
                                  Phone, Email, Description)];
Contact[] searchContacts = (Contact[])searchList[0];

for (Contact c : searchContacts) {
   System.debug(c.LastName + ',' + c.FirstName);
}

So even with the above the challenge still returns with an error of:
 
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.

 
Best Answer chosen by William Rohrbach 1
Jason NiebauerJason Niebauer
I had the same issue. I was able to pass the challenge by connecting to a fresh dev org, inserting the contact, and executing the SOSL statement.

All Answers

Ashmi PatelAshmi Patel
you can make a method for this..i  show u example..
public class AccountsController {
  @AuraEnabled
  public static List<Account> getAccounts() {
    return [SELECT Id, name, industry, Type, NumberOfEmployees, TickerSymbol, Phone
    FROM Account ORDER BY createdDate ASC];
  }
}
Pat PenaherreraPat Penaherrera
I am having the same issue with the challenge.  So close to earning the badge. :(  Below is my code snippet from the Execute Anonymous Window.
 
List<List<SObject>> searchResults = [FIND 'Mission Control' in ALL FIELDS RETURNING Contact(Id, FirstName, LastName)];
Contact[] searchedContacts = searchResults[0];

for(Contact c: searchedContacts){
    system.debug(c.LastName + ', ' + c.FirstName);
}

And below is my output in the log file generated from the above.
 
10:19:56:015 USER_DEBUG [5]|DEBUG|Dent, Brian

 
Jason NiebauerJason Niebauer
I had the same issue. I was able to pass the challenge by connecting to a fresh dev org, inserting the contact, and executing the SOSL statement.
This was selected as the best answer
William Rohrbach 1William Rohrbach 1
Thank you... I just did the same with a different dev org and was able to complete the challenge.
Pat PenaherreraPat Penaherrera
Same here!  I tried with a different developer org, and I was able to complete the challenge and earn the badge.  Thank you!
Jason NiebauerJason Niebauer
William, can you please mark my response as the best answer?
Raj KaushikRaj Kaushik
I am having the same issue. In my Debug log I see:
20:06:07:026 USER_DEBUG [7]|DEBUG|Found following Contacts Dent,Brian

My question is how to connect to a different or fresh developer organization. 
- If I create a fresh login - how the badges will transfer to my original org.
William Rohrbach 1William Rohrbach 1
You can connect your Trailhead to multiple developer organizations. When you connect it will be added to the drop down list of orgs that is shown in the "Launch..." button above the challenges descriptions.
Raj KaushikRaj Kaushik
OK may be I am missing something. I have created a brand new organization (used another email).
- Connected to this new organization from my trail playground
- took the challenge again 

result in log file:
11:18:18:060 USER_DEBUG [7]|DEBUG|Dent,Brian

Still can't pass the challenge.

RESULT:
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.
Raj KaushikRaj Kaushik
Challenge completed. I don't know how it is resolved. 

Failed:
List<List<SObject>> contacts = [FIND 'Mission Control' IN ALL FIELDS RETURNING Contact(FirstName, LastName, Phone, Email, Title)];
System.debug(contact);
System.debug(contact.LastName  + ',' + contact.FirstName);

Success:
List<List<SObject>> searchResults = [FIND 'Mission Control' in ALL FIELDS RETURNING Contact(Id, FirstName, LastName)];
//System.debug(contact);
System.debug(contact.LastName  + ',' + contact.FirstName);;

Probable Conclusion: provide minimum what challenges are looking for. Anything extra may hurt.


 
James BenningtonJames Bennington
Make sure you don't have any transaction security policies that are interfering. Check your logs to see Operation. I had one that was titled "newurl" tied to "newurlpolicycondition". I first deleted newurl under transaction security policies, and then deleted the newurlpolicycondition. After doing so and making sure there was a space in the line of code below I was finally able to pass. No new environment needed.
 
System.debug(contact.LastName  + ',SPACEGOESHERE' + contact.FirstName);
jani ikonomijani ikonomi
I tried the first solution proposed in this page  +  System.debug(contact.LastName  + ',SPACEGOESHERE' + contact.FirstName); 

be careful about the space after comma (,) 
Challenge completed!
Starr LimStarr Lim
User-added imageAnyone? Tried in another trailhead playground, still unable to get it right..
Carlos OquendoCarlos Oquendo
Hi Starr Lim, 

Try it with the Pat Penaherrera code, I had the same problem but with that code, it solve
Anne Librach 7Anne Librach 7
Hi,

I am having the same issues and i have logged into three different dev orgs.  Still getting the same error.  Would really like to get this badge.  Thanks!
Suman Kumar 63Suman Kumar 63
The Space is the culprit here make sure to use below line :

System.debug(c.LastName+', '+C.FirstName);
Albert LleberiaAlbert Lleberia
Hi, 

It's even easier than that, I had the same issue with creating contacts with the SOQL and there's no need to create a new dev org. You just need to locate a Trigger you created in a previous Trailhead module named 'ExampleTrigger' which sends an email after insert, just delete that trigger and you're ready to go.

Hope it helps!
kaustubh priy jaiswalkaustubh priy jaiswal
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);
}

having the same issue but don't know-how in 3rd-time challenge passed. try the above code maybe that help , if not try in a fresh org 
Ait Ahmed IsmailAit Ahmed Ismail
Here is the solution:
execute this snippet code first on your Execute Anonymous:

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;


Reopen Execute Anonymous Windows and execute this 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('Found the following contacts:');
for (Contact c : searchContacts) {
   System.debug(c.LastName + ', ' + c.FirstName);
}


It should pass correctly.
 
Caleb Kuester 27Caleb Kuester 27
I know that this is the old attempt, but when trying out the original code at the top of this, the only problem was that he used c.LastName + ',' + c.FirstName instead of c.LastName + ', ' + c.FirstName
(missing a space)