Apex Class ์์ฑ
๋ฐ์ดํฐ์์ค ๊ณ ๊ธ ์ค์ ์์ ์ฌ์ฉํ Apex ํด๋์ค๋ฅผ ์์ฑํ๋ ค๋ฉด ๋ฐ๋์ SBLS.DataSourceService.Fetchable ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํด์ผ ํฉ๋๋ค.
์ด ์ธํฐํ์ด์ค์๋ execute ๋ฉ์๋๊ฐ ํฌํจ๋์ด ์์ผ๋ฉฐ, ํด๋น ๋ฉ์๋์ ๋ฐ์ดํฐ ์ฒ๋ฆฌ๋ฅผ ์ํ ๋ก์ง ๊ตฌํ ํ ์ฒ๋ฆฌ๋ ๋ฐ์ดํฐ์ ๋ฆฌ์คํธ ๊ฐ์ ๋งคํ ์ ๋ณด๋ฅผ ๋ด์ SBLS.DataSourceService.Result ๊ฐ์ฒด๋ฅผ ๋ฐํํด์ผ ํฉ๋๋ค.
๐ธ ์์ ์ฝ๋
ํด๋น ์์ ์ฝ๋๋ ์ธ๋ถ API๋ฅผ ํธ์ถํ์ฌ ์ ํ ์ฝ๋๋ณ ์ฌ๊ณ ์๋์ ๊ฐ์ ธ์จ ํ, ๋ฆฌ์คํธ์ ๊ฐ์ ์ด๋ก ์์ฑํ ์ฌ๊ณ ์ด(SBLS_Virtual1)์ ๋งคํํ๋ค๊ณ ๊ฐ์ ํ์์ต๋๋ค.
SBLS.DataSourceService.Fetchable ์ธํฐํ์ด์ค๋ ํจํค์ง์์ ์ ๊ณต๋๋ ์ธํฐํ์ด์ค์ด๋ฏ๋ก, ํจํค์ง ์ธ๋ถ์์ ์ ๊ทผํ๋ ค๋ฉด Apex ํด๋์ค์ ์ ๊ณต๋๋ ๋ฉ์๋ ๋ชจ๋ global๋ก ์ ์ธํด์ผ ํฉ๋๋ค.
global class DataSourceInventory implements SBLS.DataSourceService.Fetchable {
global SBLS.DataSourceService.Result execute(SBLS.DataSourceService.Parameter params) {
// ๋ฆฌ์คํธ์ ๊ฒ์๋ ๋ ์ฝ๋
List<SObject> records = params.gets();
// ์ธ๋ถ API๋ฅผ ํธ์ถํ์ฌ ๋ฐ์ดํฐ์์ค ๊ฐ ๊ฐ์ ธ์ค๊ธฐ (์: ์ฌ๊ณ ์ ๋ณด)
// ํค: ์ ํ ์ฝ๋, ๊ฐ: ์ฌ๊ณ ์๋
Map<String, Integer> inventoryData = new Map<String, Integer>();
inventoryData.put('Product001', 10);
inventoryData.put('Product002', 20);
// ๊ฒฐ๊ณผ ๊ฐ์ฒด ์์ฑ
SBLS.DataSourceService.Result result = new SBLS.DataSourceService.Result();
// ๋ฆฌ์คํธ ๊ฐ์ฒด์ ๋ฐ์ดํฐ์์ค ๋งคํ
for (String productCode : inventoryData.keySet()) {
SBLS.DataSourceService.Action action = new SBLS.DataSourceService.Action();
action.setKeyValue(productCode); // ๋ฆฌ์คํธ ๋ ์ฝ๋์ ๋งคํํ Key ๊ฐ ์ค์
action.putSourceToTargetField(
inventoryData.get(productCode), // ๋ฐ์ดํฐ์์ค ๊ฐ: ์ฌ๊ณ ์ ๋ณด
'SBLS_Virtual1' // ๋ฆฌ์คํธ ๊ฐ์ ์ด API๋ช
);
result.addAction(action); // Action ์ถ๊ฐ
}
return result; // ๊ฒฐ๊ณผ ๋ฐํ
}
}๋ฐ์ดํฐ์์ค ๊ฐ ์ค๋น
์ธ๋ถ API ์๋ฒ์์ ๋ฐ์ดํฐ๋ฅผ ํธ์ถํ์ฌ ์ฌ๊ณ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์จ๋ค๊ณ ๊ฐ์ ํฉ๋๋ค.
์์์์๋ ์ ํ ์ฝ๋(
ProductCode)๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ฌ๊ณ ์ ๋ณด๋ฅผ ๋งคํํฉ๋๋ค.
<String, Integer> inventoryData = new Map<String, Integer>();
inventoryData.put('Product001', 10);
inventoryData.put('Product002', 20);๊ฒฐ๊ณผ ์์ฑ
SBLS.DataSourceService.Action๊ฐ์ฒด๋ฅผ ์์ฑํ์ฌ ๋ฐ์ดํฐ์์ค ๊ฐ(์ฌ๊ณ ์ ๋ณด)์ ๊ฐ์ ์ด ์ฌ๊ณ (SBLS_Virtual01)์ ๋งคํํฉ๋๋ค.์์ฑ๋ Action ๊ฐ์ฒด๋ฅผ
SBLS.DataSourceService.Result์ ์ถ๊ฐํฉ๋๋ค.
// ๊ฒฐ๊ณผ ๊ฐ์ฒด ์์ฑ
SBLS.DataSourceService.Result result = new SBLS.DataSourceService.Result();
// ๋ฆฌ์คํธ ๊ฐ์ฒด์ ๋ฐ์ดํฐ์์ค ๋งคํ
for (String productCode : inventoryData.keySet()) {
SBLS.DataSourceService.Action action = new SBLS.DataSourceService.Action();
action.setKeyValue(productCode); // ๋ฆฌ์คํธ ๋ ์ฝ๋์ ๋งคํํ Key ๊ฐ ์ค์
action.putSourceToTargetField(
inventoryData.get(productCode), // ๋ฐ์ดํฐ์์ค ๊ฐ: ์ฌ๊ณ ์ ๋ณด
'SBLS_Virtual1' // ๋ฆฌ์คํธ ๊ฐ์ ์ด API๋ช
);
result.addAction(action); // Action ์ถ๊ฐ
}๐ธ SBLS.DataSourceService.Parameter
๋ฆฌ์คํธ์ ์ ๋ณด๋ฅผ ๊ฐ์ง ๊ฐ์ฒด์ ๋๋ค. ๋น๋์์ ์ ํํ ํ๋์ ๊ฐ๋ง ๋ด๊ฒจ์์ต๋๋ค.
์์ ์ฝ๋
global SBLS.DataSourceService.Result execute(SBLS.DataSourceService.Parameter params) {
List<SObject> records = params.gets();
...
}Method
List<SObject> gets()
๊ฒ์๋ ๋ ์ฝ๋๋ฅผ ๋ฐํํฉ๋๋ค. ๋น๋์์ ์ถ๊ฐํ ํ๋ผ๋ฏธํฐ๊ฐ ์๋ ๊ฒฝ์ฐ, ๊ฐ์ ๋น์ด ์์ต๋๋ค.
๐ธ SBLS.DataSourceService.Result
๋ฆฌ์คํธ์ ๋ฐ์ดํฐ์์ค ๊ฐ์ ๋ชจ๋ ๋งคํ ์ ๋ณด๋ฅผ ๋ด์ ๋ฆฌ์คํธ๋ก ๋ฐํํ๋ ๊ฐ์ฒด์
๋๋ค. ๋งคํ ์ ๋ณด๋ SBLS.DataSourceService.Action ๊ฐ์ฒด์ ์ ์ฅํ ๋ค, SBLS.DataSourceService.Result ๊ฐ์ฒด์ ์ถ๊ฐํ์ฌ ๋ฐํํฉ๋๋ค.
์์ ์ฝ๋
...
SBLS.DataSourceService.Result result = new SBLS.DataSourceService.Result();
for(String productCode : inventoryData.keySet()) {
// SBLI.DataSourceService.Action ๊ฐ์ฒด์ ๋งคํ ์ ๋ณด ์ ์ฅ
SBLS.DataSourceService.Action action = new SBLS.DataSourceService.Action();
action.setKayValue(productCode);
action.putSourceToTargetField(
inventoryData.get(productCode),
'SBLS_Virtual1'
);
result.addAction(action); // ๋งคํ ์ ๋ณด๊ฐ ๋ด๊ธด Action์ Result์ ์ถ๊ฐ
}
return result;Method
addAction(SBLS.DataSourceService.Action action)
๋งคํ ์ ๋ณด๊ฐ ๋ด๊ธด Action ๊ฐ์ฒด๋ฅผ Result ๊ฐ์ฒด์ ์ถ๊ฐํฉ๋๋ค.
action
๋ฆฌ์คํธ์ ๋ฐ์ดํฐ์์ค ๊ฐ์ ๋งคํํ ์ ๋ณด๋ฅผ ๋ด์ ๊ฐ์ฒด์ ๋๋ค.
๐ธ SBLS.DataSourceService.Action
๋ฆฌ์คํธ์ ๋ฐ์ดํฐ์์ค ๊ฐ์ ๋งคํํ ์ ๋ณด๋ฅผ ๋ด์ ๊ฐ์ฒด์ ๋๋ค.
์์ ์ฝ๋
SBLS.DataSourceService.Result result = new SBLS.DataSourceService.Result();
// ๋ฐ์ดํฐ์์ค์์ ๊ฐ ์ ํ์ฝ๋์ ์ฌ๊ณ ์ ๋ณด๋ฅผ ๋ฐ๋ณต ์ฒ๋ฆฌ
for(String productCode : inventoryData.keySet()) {
SBLS.DataSourceService.Action action = new SBLS.DataSourceService.Action();
// ์ ํ์ฝ๋๋ฅผ Key ๊ฐ์ผ๋ก ์ค์ ํ์ฌ ์กฐํ/๋ผ์ธ ์์ดํ
๊ณผ ๋งคํ
action.setKayValue(productCode);
// ์ฌ๊ณ ์ ๋ณด๋ฅผ ์กฐํ/๋ผ์ธ ์์ดํ
์ Inventory__c ํ๋์ ๋งคํ
action.putSourceToTargetField(
inventoryData.get(productCode), // ๋ฐ์ดํฐ์์ค ๊ฐ: ์ฌ๊ณ
'SBLS_Virtual1' // ๊ฐ์ ์ด API๋ช
);
result.addAction(action); // ๋งคํ ์ ๋ณด ์ถ๊ฐ
}
return result; // ์ต์ข
๊ฒฐ๊ณผ ๋ฐํMethod
setKeyValue(Object keyValue)
๋ฆฌ์คํธ์ Key์ ์ผ์นํ๋ ๋ฐ์ดํฐ์์ค์ Key ๊ฐ์ ์ค์ ํฉ๋๋ค.
keyValue
Object
๋ฐ์ดํฐ์์ค์ Key ๊ฐ์ ๋๋ค.
putSourceToTargetField(Object sourceValue, String targetFieldApiName)
๋ฐ์ดํฐ์์ค ๊ฐ์ ์ํ๋ ๋ฆฌ์คํธ ํ๋ ๋๋ ๊ฐ์ ์ด์ ํ ๋นํฉ๋๋ค.
sourceValue
Object
๋ฐ์ดํฐ์์ค ๊ฐ์ ๋๋ค.
targetFieldApiName
String
๋ฆฌ์คํธ์ ํ๋ ๋๋ ๊ฐ์ ์ด์ API๋ช ์ ๋๋ค.
Last updated
Was this helpful?