You need to sign in to do that
Don't have an account?
RAMANJINEYULU 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?
{
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?
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
Thanks
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;