[Hands-on Challenge] - Salesforce
Create an Apex class that returns contacts based on incoming parameters.
https://trailhead.salesforce.com/ko/content/learn/modules/apex_database/apex_database_soql
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.
- The Apex class must be called ContactSearch and be in the public scope
- The Apex class must have a public static method called searchForContacts
- The method must accept two incoming strings as parameters
- The method should then find any contact that has a last name matching the first string, and mailing postal code (API name: MailingPostalCode) matching the second string
- The method should finally return a list of Contact records of type List that includes the ID and Name fields
//Create an Apex class that returns contacts based on incoming parameters.
// 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.
//The Apex class must be called ContactSearch and be in the public scope
//The Apex class must have a public static method called searchForContacts
//The method must accept two incoming strings as parameters
//The method should then find any contact that has a last name matching the first string, and mailing postal code (API name: MailingPostalCode) matching the second string
//The method should finally return a list of Contact records of type List that includes the ID and Name fields
//즉 검색기능임. 성과 우편번호를 입력하고 그에 해당하는 조건을 반환
public with sharing class ContactSearch {
public static List<Contact> searchForContacts(String lastName, String PostalCode) { //성과 우편번호를 입력받음
List<Contact>contacts = [
SELECT ID, Name, LastName, MailingPostalCode
FROM Contact
WHERE LastName = :lastName AND MailingPostalCode = :PostalCode
];
System.debug(contacts);
return contacts;
}
}