Apex 작업 생성 준비
학습 목표
이 유닛을 완료하면 다음을 수행할 수 있습니다.
- 조직에서 작업을 구축할 수 있도록 준비합니다.
- Apex가 작업을 수행할 수 있도록 준비되었는지 확인합니다.
오늘의 날씨: 맑은 하늘
휴가를 떠나 본 사람이라면 누구나 알겠지만, 여행을 계획대로 최대한 즐기기 위해서는 날씨를 반드시 확인해야 합니다. 날씨가 항상 맑을 수는 없지만, Coral Cloud Resorts의 방문객들도 화창하고 따뜻한 날씨를 기대할 수 있습니다. 날씨와 상관없이 고객들이 숙박을 최대한 즐길 수 있도록, Coral Cloud 팀은 AI 에이전트에 날씨 정보를 수집하는 기능을 추가하고자 합니다. 이를 위해서는 외부 API를 사용하여 Apex 클래스에서 날씨 데이터를 가져오는 작업을 생성해야 합니다.
Agentforce가 포함된 Developer Edition 조직에 가입
이 모듈을 완료하려면 Agentforce와 샘플 데이터가 포함된 특별한 Developer Edition 조직이 필요합니다. 링크를 클릭하여 Agentforce가 포함된 무료 맞춤형 Developer Edition 조직에 가입하고, Trailhead에 연결하여 이 모듈의 과제를 완료하세요. 이 조직은 이 뱃지의 도전 과제와 함께 작동하도록 설계되었으며 다른 뱃지에서는 작동하지 않을 수 있습니다. 항상 Trailhead Playground 또는 권장되는 Developer Edition 특별 조직을 사용하고 있는지 확인하세요.
-
Agentforce가 포함된 Developer Edition 조직에 무료로 가입하세요.
- 양식을 입력합니다.
- Email(이메일)에는 유효한 이메일 주소를 입력합니다.
- Username(사용자 이름)에는 이메일 주소 형식의 고유한 사용자 이름을 입력합니다. 이 경우 유효한 이메일 계정이 아니어도 됩니다(예: yourname@example.com).
- Email(이메일)에는 유효한 이메일 주소를 입력합니다.
- 양식을 작성한 후 Sign me up(가입)을 클릭합니다. 확인 메시지가 나타납니다.
- 활성화 이메일을 수신하면(몇 분 걸릴 수 있음) 이메일을 열고 Verify Account(계정 확인)를 클릭합니다.
- 비밀번호와 응답 질문을 설정하여 등록을 완료합니다. 팁: 나중에 쉽게 사용할 수 있도록 비밀번호 관리자와 같은 안전한 곳에 사용자 이름, 비밀번호, 로그인 URL을 저장해 두세요.
- Developer Edition에 로그인했습니다.
이제 새 Developer Edition 조직을 Trailhead에 연결합니다.
- 자신의 Trailhead 계정에 로그인했는지 확인합니다.
- 이 페이지 하단의 Challenge(과제) 섹션에서 조직 이름을 클릭하고 Connect Org(조직 연결)를 클릭합니다.
- 로그인 화면에서 방금 설정한 Developer Edition의 사용자 이름과 비밀번호를 입력합니다.
- Allow Access?(액세스를 허용하시겠어요?) 화면에서 Allow(허용)를 클릭합니다.
- Want to connect this org for hands-on challenges?(실습 과제를 위해 이 조직을 연결하시겠어요?) 화면에서 Yes! Save it(예! 저장합니다)을 클릭합니다. 그러면 과제 페이지로 리디렉션되며 새 Developer Edition을 사용하여 이 뱃지를 획득할 수 있습니다.
에이전트를 위한 조직 준비
에이전트를 사용자 정의하려면 필요한 조직 기능을 모두 활성화하세요.
- Setup(설정)(
) 아이콘을 클릭하고 Setup(설정)을 선택합니다.
- Setup Quick Find(설정 빠른 찾기) 상자에서 Einstein Setup(Einstein 설정)을 검색하여 선택합니다.
- Einstein이 On(설정) 상태인지 확인합니다. 이미 On(설정) 상태인 경우 Off(해제)로 변경한 후 다시 On(설정)으로 변경합니다.

- 브라우저를 새로 고쳐 설정을 다시 로드합니다.
- Quick Find(빠른 찾기)에서 Salesforce Go를 검색하여 선택합니다.
- Search features...(기능 검색...) 텍스트 상자에 Agentforce (Default)(Agentforce(기본값))를 입력하여 선택합니다.

-
Get Started(시작하기)를 클릭합니다.
-
Turn On(활성화)을 클릭합니다.
-
Confirm(확인)을 클릭합니다.
이미 보유한 기능으로 에이전트 작업 구축하기
좋습니다! 이제 에이전트용 맞춤 작업을 구축할 준비가 거의 끝났습니다. Salesforce로 AI 에이전트를 구축하는 경우의 큰 장점 중 하나는 조직에 이미 구축되어 있는 기능을 활용할 수 있다는 것입니다. 이 경우 Coral Cloud Resort의 날씨 정보를 AI 에이전트에 추가하려고 합니다. Coral Cloud에는 외부 API에서 Coral Cloud Resort 위치의 날씨를 가져오기 위한 WeatherService Apex 클래스가 이미 있습니다. 이제 이 기능이 작업에 어떻게 적용되는지 살펴보겠습니다.
public with sharing class WeatherService {
/**
* Gets the weather at Coral Cloud Resorts for the provided date
*/
public static Weather getResortWeather(Datetime dateToCheck) {
Integer currentYear = Date.today().year();
Integer yearDelta = currentYear - dateToCheck.year();
dateToCheck = dateToCheck.addYears(yearDelta);
String isoDate = dateToCheck.format('yyyy-MM-dd');
String dateString = dateToCheck.format('MMMM d');
// Prepare API request
HttpRequest req = new HttpRequest();
req.setEndpoint(
'callout:Weather_Endpoint/weather?lat=37.789782764570425&lon=-122.39723702244089&date=' +
isoDate
);
req.setMethod('GET');
// Make callout
Http http = new Http();
HttpResponse res = http.send(req);
if (res.getStatusCode() != 200) {
throw new CalloutException('Bad response: ' + res);
}
// The response contains a list of temperatures for different times of the day
// We parse the response and find the min and max temperatures
String body = res.getBody();
WeatherApiResponse weatherResponse = (WeatherApiResponse) JSON.deserialize(
body,
WeatherAPIResponse.class
);
List<Decimal> temperatures = new List<Decimal>();
for (TemperatureWrapper item : weatherResponse.weather) {
if (item.temperature != null) {
temperatures.add(item.temperature);
}
}
temperatures.sort();
// Prepare temperatures and description
Decimal minTempC = temperatures[0];
Decimal maxTempC = temperatures[temperatures.size() - 1];
Decimal minTempF = toFahrenheit(minTempC);
Decimal maxTempF = toFahrenheit(maxTempC);
String description =
'On ' +
dateString +
', temperature should be between ' +
minTempC +
'°C (' +
minTempF +
'°F) and ' +
maxTempC +
'°C (' +
maxTempF +
'°F) at Coral Cloud Resorts.';
// Return weather info
Weather weather = new Weather();
weather.minTemperatureC = minTempC;
weather.minTemperatureF = minTempF;
weather.maxTemperatureC = maxTempC;
weather.maxTemperatureF = maxTempF;
weather.description = description;
return weather;
}
private static Decimal toFahrenheit(Decimal celsius) {
return (celsius * 9 / 5 + 32).setScale(1);
}
private class WeatherApiResponse {
public List<TemperatureWrapper> weather;
}
private class TemperatureWrapper {
public Decimal temperature;
}
public class Weather {
public Decimal minTemperatureC;
public Decimal minTemperatureF;
public Decimal maxTemperatureC;
public Decimal maxTemperatureF;
public String description;
}
}이는 입력된 날짜의 날씨를 가져오기 위해 날씨 서비스에 HTTP 요청을 보내는 간단한 Apex 클래스입니다. 하지만 이 Apex 클래스는 Agentforce 빌더에서 사용할 수 없습니다. 이 클래스를 업데이트하여 호출 가능한 메서드로 만들 수도 있지만, 기존 WeatherService를 호출하는 InvocableMethod로 설정된 새로운 Apex 클래스를 생성하는 것이 모범 사례입니다. InvocableMethod 주석을 사용하면 Flow와 같은 선언형 도구, REST를 통한 외부 애플리케이션, 그리고 Agentforce에서 맞춤형 Apex 코드를 호출할 수 있습니다.
다행히 Coral Cloud 팀은 이미 WeatherService를 호출하는 Apex 클래스를 구축해 두었습니다. 이제 해당 클래스를 살펴보고 WeatherService를 어떻게 구현하는지 확인해 보겠습니다.
public with sharing class CheckWeather {
@InvocableMethod(
label='Check Weather'
description='Check weather at Coral Cloud Resorts at a specific date'
)
public static List<WeatherResponse> getWeather(
List<WeatherRequest> requests
) {
// Retrieve the date for which we want to check the weather
Datetime dateToCheck = (Datetime) requests[0].dateToCheck;
WeatherService.Weather weather = WeatherService.getResortWeather(
dateToCheck
);
// Create the response for Copilot
WeatherResponse response = new WeatherResponse();
response.minTemperature = weather.minTemperatureC;
response.maxTemperature = weather.maxTemperatureC;
response.temperatureDescription =
'Temperatures will be between ' +
weather.minTemperatureC +
'°C (' +
weather.minTemperatureF +
'°F) and ' +
weather.maxTemperatureC +
'°C (' +
weather.maxTemperatureF +
'°F) at Coral Cloud.';
return new List<WeatherResponse>{ response };
}
public class WeatherRequest {
@InvocableVariable(
required=true
description='Date for which we want to check the temperature. The variable needs to be an Apex Date type with format yyyy-MM-dd.'
)
public Date dateToCheck;
}
public class WeatherResponse {
@InvocableVariable(
description='Minimum temperature in Celsius at Coral Cloud Resorts location for the provided date'
)
public Decimal minTemperature;
@InvocableVariable(
description='Maximum temperature in Celsius at Coral Cloud Resorts location for the provided date'
)
public Decimal maxTemperature;
@InvocableVariable(
description='Description of temperatures at Coral Cloud Resorts location for the provided date'
)
public String temperatureDescription;
}
}가장 먼저 눈에 띄는 것은 getWeather 메서드에 적용된 @InvocableMethod 주석입니다. 전달되는 두 개의 매개변수는 에이전트 작업 생성 프로세스에서 사용됩니다. label 매개변수는 에이전트 작업 레이블로 표시됩니다. description 매개변수는 에이전트 작업 지침으로 표시됩니다. 설명은 AI 에이전트 및 에이전트가 메서드를 이해하는 방식에서 매우 중요합니다.
다음으로는 에이전트 생성 작업의 입력과 출력에 각각 사용되는 @InvocableVariable 주석이 적용된 두 개의 public 클래스 WeatherRequest 및 WeatherResponse가 있습니다.
WeatherRequest의 경우 dateToCheck에 대한 @InvocableVariable 주석에 required 매개변수가 true로 설정되어 있습니다. 이로 인해 에이전트 생성 작업의 Require Input(필수 입력) 설정이 기본적으로 체크됩니다. description 매개변수는 입력 지침으로 표시됩니다. 또한 dateToCheck의 변수 유형을 Date로 설정하면 입력 데이터 형식이 설정됩니다.
WeatherResponse의 경우, minTemperature, maxTemperature, temperatureDescription이라는 세 개의 변수가 @InvocableVariable 주석과 함께 존재합니다. 각 변수에는 에이전트 생성 작업의 출력 지침에 표시되는 description 매개변수가 설정되어 있습니다. 또한 변수 유형인 Decimal, Decimal, String은 출력 렌더링으로 표시됩니다. String 변수 유형은 출력 렌더링에서 텍스트로 설정됩니다.
권한 설정
다른 모든 Apex 기능과 마찬가지로, Apex 파일에 대한 올바른 액세스 권한이 필요합니다. 이 단계는 이 뱃지를 위해 사용 중인 맞춤형 개발자 조직에서 이미 완료되어 있습니다. 권한 집합을 통해 Invocable 메서드를 포함한 Apex 클래스에 AI 에이전트가 액세스할 수 있도록 이미 권한이 설정되어 있습니다. 그렇지 않았다면 작업을 생성하고 에이전트에 추가했더라도 에이전트는 플랜을 수립할 때 해당 작업을 고려할 수 없었을 것입니다. 적절한 권한의 부족은 Agentforce에서 Apex 작업이 예상한 대로 작동하지 않는 주요 원인 중 하나입니다.
이제 Apex를 작업에 사용하려면 무엇이 필요한지 더 상세히 알게 되었습니다. 내용이 다소 많다고 느껴질 수 있지만, 다음 유닛에서 실제로 작업을 구축해 보면 더 명확하게 이해할 수 있습니다.
