Skip to content

Instantly share code, notes, and snippets.

@forcethesales
Last active October 31, 2021 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forcethesales/413a8def15b6433a5c5afcc92b898ca2 to your computer and use it in GitHub Desktop.
Save forcethesales/413a8def15b6433a5c5afcc92b898ca2 to your computer and use it in GitHub Desktop.
RADWomenII Week 2 Homework
//Trailhead Write SOQL Queries unit. For this challenge, you will need to create a class that has a method accepting two strings.
//The method searches for contacts that have a last name matching the first string and a mailing postal code matching the second. It gets the ID and Name of those contacts
//and returns them
public class ContactSearch {
//delare a method accepting two strings
public static List< Contact > searchForContacts (String firstString, String secondString) {
List < Contact > folks = [SELECT ID, FirstName, LastName
FROM Contact
WHERE LastName=:firstString
AND MailingPostalCode =:secondString
];
system.debug(folks);
return folks;
//Test in Execute Anonymous with: ContactSearch.SearchforContacts('Young','66405');
}
}
Trailhead Write SOSL Queries Unit.
public class ContactAndLeadSearch {
//a public static method that accepts an incoming string as a parameter
public static List<List<sObject>> searchContactsAndLeads (String incoming) {
//write a SOSQL query to search by lead or contact name fields for the incoming string.
List<List<sObject>> searchList = [FIND :incoming IN NAME FIELDS
RETURNING Contact(FirstName,LastName),Lead(FirstName,LastName)];
//return the list of the same kind
return searchList;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment