Skip to main content

데이터를 Apex에 반환하는 SOQL 작성

참고

참고

한국어로 학습하시겠어요? 이 배지에서는 Trailhead 실습과제 검증이 영어로 진행됩니다. 참조용 번역이 괄호로 제공됩니다. Trailhead Playground에서 (1) 로캘을 미국으로 바꾸고 (2) 언어를 영어로 바꾼 후 (3) 영문으로 표시된 값을 복사해 붙여 넣으세요. 여기 에 나와 있는 지침을 따르세요.

원하는 언어로 Trailhead 사용하기 배지를 확인해 현지화된 Trailhead 경험을 활용하는 방법에 대해 자세히 알아보세요.

Trail Together와 함께 알아보기

이 단계를 전문가와 함께 진행하고 싶으신가요? Trail Together 시리즈의 일부인 이 비디오를 시청하세요.

(이 영상은 24분 15초부터 시작합니다. 단계 시작 부분으로 되돌려 다시 시청하려는 경우 참고하세요.)

쿼리 만들기

전에 만든 Recruiting Account(채용 계좌) 레코드를 검색하는 SOQL 쿼리를 만듭니다.

  1. Developer Console에서 File(파일) | Open Resource(리소스 열기)를 클릭합니다.
  2. Account.obj를 선택한 후 Open(열기)을 클릭합니다.
  3. IdName(이름)을 선택합니다. 여러 필드를 선택하려면 CTRL(Windows) 또는 CMD(Mac)를 사용합니다.
  4. Query(쿼리)를 클릭합니다.
  5. 쿼리 편집기에 쿼리 작성 지침이 표시되면 Query(쿼리)를 다시 클릭합니다.
  6. 쿼리 끝에 WHERE Name = 'Recruiting'을 입력합니다.
  7. SOQL 쿼리가 다음과 같이 표시되는지 확인합니다.
    SELECT Id, Name FROM Account WHERE Name = 'Recruiting'
  8. Execute(실행)를 클릭하여 쿼리를 실행하고 결과를 표시합니다.

새로 만든 Contact(연락처)를 Recruiting Account(채용 계좌)와 연결하고 SOQL 쿼리를 createContact 메서드에 추가합니다.

  1. CreateContactFromCan 클래스에서 기존 코드를 다음 코드로 바꿉니다.
    public with sharing class CreateContactFromCan {
        //Declare a method that returns void and accepts a Candidate list named candsFromTrigger
        public static void createContact (List<Candidate__c> candsFromTrigger) {
            //Select the Recruiting account from the database and add it to a list
            //named candAccts (from the Account class)
            List<Account> candAccts = [SELECT Id, Name FROM Account WHERE Name = 'Recruiting'];
            //Instantiate a Contact list named conList
            List<Contact> conList = new List<Contact>();
            //Declare a FOR list loop that uses an iteration variable named currentCandidate
            //to loop through the candsFromTrigger list
            for(Candidate__c currentCandidate:candsFromTrigger) {
                //Create a Contact and add it to conList
                //Set the FirstName, LastName, and Email attributes to match the
                //corresponding attributes of the currentCandidate object (First_Name__c,
                //Last_Name__c, and Email__c)
                conList.add(new Contact(
                    AccountId = candAccts[0].Id,
                    FirstName = currentCandidate.First_Name__c,
                    LastName = currentCandidate.Last_Name__c,
                    Email = currentCandidate.Email__c)
                );
            }
            //Save conList to the database
            Database.insert(conList);
        }
    }
  2. CreateContactFromCan 클래스를 저장합니다.
Salesforce 도움말에서 Trailhead 피드백을 공유하세요.

Trailhead에 관한 여러분의 의견에 귀 기울이겠습니다. 이제 Salesforce 도움말 사이트에서 언제든지 새로운 피드백 양식을 작성할 수 있습니다.

자세히 알아보기 의견 공유하기