Skip to main content

DML을 사용하여 sObjects를 데이터베이스에 저장

참고

참고

한국어로 학습하시겠어요? 이 배지에서는 Trailhead 실습과제 검증이 영어로 진행됩니다. 참조용 번역이 괄호로 제공됩니다. 영문으로 표시된 값을 복사하여 붙여 넣은 다음 Trailhead Playground 언어를 영어로, 로캘을 미국으로 전환하세요. 여기 에 나와 있는 지침을 따르세요.

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

Trail Together와 함께 알아보기

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

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

sObjects 만들기 및 조정

Recruiting Account(채용 계좌) sObject를 만들고 데이터베이스에 저장합니다. 

  1. Developer Console에서 Execute Anonymous(익명 실행) 창을 엽니다.
  2. 기존 코드를 다음 코드로 바꿉니다.
    //From the Account class, instantiate an object named acct
    Account acct = new Account();
    //Set the name attribute of the acct object to Recruiting
    acct.name='Recruiting';
    //Use DML to save the acct object to the database
    Database.insert(acct);
    System.debug('A new account named ' + acct.name + ' was added ');
  3. Open Log(로그 열기)가 선택되어 있는지 확인한 후 Execute(실행)를 클릭합니다. 실행 로그가 열립니다.
  4. Debug Only(디버그만)를 선택합니다.
  5. 디버그 메시지를 검토한 후 로그를 닫습니다.

createContact 메서드 안에 Contact(연락처) sObject를 만들고, 해당 특성을 채우고, 이 sObject를 conList에 추가하고, 목록을 데이터베이스에 저장합니다.

  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) {
            //Instantiate a Contact list named conList
            List<Contact> conList = new List<Contact>();
            //Declare a list FOR 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(
                    //Set the AccountId for the contact(we'll do this in the next unit)
                    //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 클래스를 저장합니다.
계속해서 무료로 학습하세요!
계속 진행하려면 계정을 가입하세요.
얻을 수 있는 이점
  • 커리어 목표에 대한 개인화된 권장 사항 제공받기
  • 실습 과제 및 퀴즈를 통해 스킬 연습
  • 진행 상황을 추적하고 고용주에게 공유
  • 멘토십과 커리어 기회에 연결