Salesforce

[Hands-on Challenge] Create an Apex class that returns both contacts and leads based on a parameter - Salesforce

송테이토 2023. 2. 12. 18:07

매개 변수와 일치하는 이름 또는 성을 가진 연락처와 리드를 모두 반환하는 클래스

Create an Apex class that returns both contacts and leads based on a parameter.

To pass this challenge, create an Apex class that returns both contacts and leads that have first or last name matching the incoming parameter.
  • The Apex class must be called ContactAndLeadSearch and be in the public scope
  • The Apex class must have a public static method called searchContactsAndLeads
    • The method must accept an incoming string as a parameter
    • The method should then find any contact or lead that matches the string as part of either the first or last name
    • The method should finally use a return type of List<List< sObject>>
  • NOTE: Because SOSL indexes data for searching, you must create a Contact record and Lead record before checking this challenge. Both records must have the last name Smith. The challenge uses these records for the SOSL search

 


//Create an Apex class that returns both contacts and leads based on a parameter.

//To pass this challenge, create an Apex class that returns both contacts and leads that have first or last name matching the incoming parameter.

//The Apex class must be called ContactAndLeadSearch and be in the public scope

//The Apex class must have a public static method called searchContactsAndLeads
//The method must accept an incoming string as a parameter
//The method should then find any contact or lead that matches the string as part of either the first or last name
//The method should finally use a return type of List<List< sObject>>

//NOTE: Because SOSL indexes data for searching, you must create a Contact record and Lead record before checking this challenge. Both records must have the last name Smith. The challenge uses these records for the SOSL search

//매개 변수와 일치하는 이름 또는 성을 가진 연락처와 리드를 모두 반환하는 클래스
public class ContactAndLeadSearch {
    public static List<List<SObject>> searchContactsAndLeads(String inputSearch) {

        List<List<sObject>> searchList = [
                FIND :inputSearch
                IN all fields
                RETURNING Contact(FirstName, LastName), Lead(FirstName, Lastname)
        ];

        system.debug('Lead : '+searchList[0]);
        system.debug('Contact :'+searchList[1]);

        //System.debug(searchList);
        return searchList;
    }
}