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
RAMANJINEYULU GOGULARAMANJINEYULU GOGULA 

Trail head SOQL Question

public class ContactSearch 
{
    public static List<Contact> searchForContacts(String s1, String s2)
    {
        ContactSearch cs=new ContactSearch();
        List<String> s3=new List<String>{s1,s2};
        s3[0]=s1;
        s3[1]=s2;
        System.debug(s3);
        List<String> sr=new String[]{''+[SELECT LastName FROM Contact],''+[SELECT MailingPostalCode FROM Contact]};
        if(s1==s3[0] && s2==s3[1])
        {
            List<Contact> result=new List<Contact>();
            Contact[] query=[SELECT Id,FirstName,LastName FROM Contact WHERE LastName=:s1 AND MailingPostalCode=:s2];            
            System.debug(query);
        }
        List<Contact> result=new List<Contact>();
        return result;
      }
}


This is the code developed by me, it is running but unable to pass the trailhead challenge? 
Best Answer chosen by RAMANJINEYULU GOGULA
RAMANJINEYULU GOGULARAMANJINEYULU GOGULA
Dear Anupama,

I resolved my issue thanks for your response.

List<Contact> result=new List<Contact>();
            Contact[] query=[SELECT Id,FirstName,LastName FROM Contact WHERE LastName=:s1 AND MailingPostalCode=:s2];      
// here I did not related  and assigned query to the list, so there is no relation. That's why I got error. 

this is what I reassigned  and below code is passing challenge.
List<Contact> allcontacts=[SELECT Id,FirstName,LastName FROM Contact WHERE LastName=:s1 AND MailingPostalCode=:s2];     
return allcontacts;

All Answers

Anupama SamantroyAnupama Samantroy
What is error shown while checking the challenge? And which trailhead module is this?

Thanks
Anupama
RAMANJINEYULU GOGULARAMANJINEYULU GOGULA
Dear Anupama,

I resolved my issue thanks for your response.

List<Contact> result=new List<Contact>();
            Contact[] query=[SELECT Id,FirstName,LastName FROM Contact WHERE LastName=:s1 AND MailingPostalCode=:s2];      
// here I did not related  and assigned query to the list, so there is no relation. That's why I got error. 

this is what I reassigned  and below code is passing challenge.
List<Contact> allcontacts=[SELECT Id,FirstName,LastName FROM Contact WHERE LastName=:s1 AND MailingPostalCode=:s2];     
return allcontacts;
This was selected as the best answer
Anupama SamantroyAnupama Samantroy
great!!! could you please close this thread by selecting your answer as best answer.