์™ธ๋ถ€ (External)

์ฃผ๋กœ ์™ธ๋ถ€ ์„œ๋ฒ„์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์กฐํšŒํ•˜์—ฌ ๊ฐ™์ด ํ‘œํ˜„ํ•ด์ฃผ๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ์ž‘์„ฑํ•œ Apex Class๋ฅผ ์ด์šฉํ•ด ๋ฐ์ดํ„ฐ์†Œ์Šค๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ๋•Œ๋ฌธ์— ๋‚ด๋ถ€ ๋ฐ์ดํ„ฐ์†Œ์Šค์— ๋น„ํ•ด ์ž์œ ๋กญ๊ฒŒ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋Š” ์žฅ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด ์™ธ๋ถ€ ์„œ๋ฒ„์—์„œ ์‹ค์‹œ๊ฐ„ ์žฌ๊ณ ๋ฅผ ๊ฐ€์ ธ์™€ ํ™”๋ฉด์— ๊ฐ™์ด ํ‘œ์‹œํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ Apex Class์—์„œ Rest API ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ์™ธ๋ถ€ ๋ฐ์ดํ„ฐ์†Œ์Šค์— ์ง€์ •ํ•˜๋ฉด Line-Item Configurator์—์„œ ํ•ด๋‹น ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์†์„ฑ

    External ๋ฐ์ดํ„ฐ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ ์†์„ฑ์ž…๋‹ˆ๋‹ค.

  • Apex Class ์ž‘์„ฑ

    External ๋ฐ์ดํ„ฐ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ „ Apex Class๋ฅผ ๋จผ์ € ์ž‘์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Package์—์„œ ์ œ๊ณตํ•˜๋Š” SBLD.DataSourceService.Fetchable ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ž‘์„ฑํ•˜๋ ค๋Š” Apex Class์— implements ํ•˜์—ฌ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

  • ์˜ˆ์‹œ

    ์ค€๋น„์ค‘์ž…๋‹ˆ๋‹ค.


์†์„ฑ

External ๋ฐ์ดํ„ฐ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ ์†์„ฑ์ž…๋‹ˆ๋‹ค.

ํ•ญ๋ชฉ์„ค๋ช…ํ•„์ˆ˜

Apex Class Name

์™ธ๋ถ€๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ฌ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํด๋ž˜์Šค์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

โœ”๏ธ

Key Field

DataSource๋ฅผ ํ†ตํ•ด ๊ฐ€์ ธ์˜จ ๋ฐ์ดํ„ฐ๋ฅผ ๋งคํ•‘์‹œํ‚ค๊ธฐ ์œ„ํ•œ field API ์ด๋ฆ„์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

โœ”๏ธ

Parent Field Parameters

DataSource์˜ Type์ด External์ผ ๊ฒฝ์šฐ Parent Object์˜ Field ์ค‘ Parameter๋กœ ๋„˜๊ฒจ์ค„ Field๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

Lookup Field Parameters

DataSource์˜ Type์ด External์ผ ๊ฒฝ์šฐ Lookup Object์˜ Field ์ค‘ Parameter๋กœ ๋„˜๊ฒจ์ค„ Field๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

Active

DataSource์˜ ํ™œ์„ฑ, ๋น„ํ™œ์„ฑ ์—ฌ๋ถ€์ž…๋‹ˆ๋‹ค.

โœ”๏ธ

Apex Class ์ž‘์„ฑ

External ๋ฐ์ดํ„ฐ์†Œ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ „ Apex Class๋ฅผ ๋จผ์ € ์ž‘์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Package์—์„œ ์ œ๊ณตํ•˜๋Š” SBLD.DataSourceService.Fetchable ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ž‘์„ฑํ•˜๋ ค๋Š” Apex Class์— implements ํ•˜์—ฌ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

SBLD.DataSourceService.Fetchable ํด๋ž˜์Šค๋ฅผ implements ํ•˜์—ฌ execute() ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

DataSourceServiceMock.cls
global with sharing class DataSourceServiceMock implements SBLD.DataSourceService.Fetchable {
    /***
     * @description SBLD.DataSourceService.Fetchable execute() ์ •์˜
     * @param param SBLD.DataSourceService.Parameterํ˜• ํŒŒ๋ผ๋ฏธํ„ฐ
     *              DataSource์—์„œ ์„ค์ •ํ•œ 
     * @return Map<Object, SObject>
     ****/
    global SBLD.DataSourceService.Result execute(SBLD.DataSourceService.Parameter param) {
        SBLD.DataSourceService.Result result = new SBLD.DataSourceService.Result();
        /**
         *  @method DataSourceService.Parameter gets()
         *  @param  String ํ˜• Parent, Lookup ์ค‘ ์„ ํƒ (๋Œ€์†Œ๋ฌธ์ž ๊ตฌ๋ถ„ ์—†์Œ)
         *  @return List<SObject>
         **/
        SObject parentRecord = null;
        List<SObject> lookupRecords = new List<SObject>();
        // Parent ๊ด€๋ จ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
        if(param.gets('parent')<>null && !param.gets('parent').isEmpty()) {
            parentRecord = param.gets('parent')[0];
        }
        // Lookup ๊ด€๋ จ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
        if(param.gets('lookup')<>null && !param.gets('lookup').isEmpty()) {
            listLookupParameters = param.gets('lookup');
        }
        /**
         * ์„ฑ๊ณต ์‹œ, External ๊ฒฐ๊ณผ๊ฐ’์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
         **/
        for(SObject sobj : lookupRecords) {
            /**
             * Internal์˜ Action๊ณผ ๋™์ผํ•˜๊ฒŒ DataSource์˜ ๊ฐ’์„ 
             * Lookup ๋˜๋Š” Line-Item ํ•„๋“œ์— ๋งคํ•‘ํ•˜๋Š” ์ž‘์—…์„ 
             **/
            SBLD.DataSourceServiceAction action = new SBLD.DataSourceServiceAction();
            // 1. External์— ์„ค์ •ํ•œ External Key ๊ฐ’
            action.setKeyValue(sobj.get('Id')); // Product Code
            // 2. External์—์„œ ๊ฐ€์ ธ์˜จ ๊ฐ’์„ Lookup ๋˜๋Š” Junction ํ•„๋“œ์— ๋งคํ•‘ํ•ฉ๋‹ˆ๋‹ค.
            Map<String, Object> mapPopulatedField = sobj.getPopulatedFieldsAsMap();
            for(String fieldName : mapPopulatedField.keySet()) {
                action.putSourceToTargetField(mapPopulatedField.get(fieldName), fieldName);
            }
            // 3. DataSourceService.Result์— Action์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
            result.addAction(action);
        }
        return result;
    }
}

SBLD.DataSourceService.Parameter์—์„œ gets() ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด Line-Item Configurator์˜ Parent ๋˜๋Š” Lookup ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

global SBLD.DataSourceService.Result execute(SBLD.DataSourceService.Parameter param) {
    SObject parentRecord = null;
    List<SObject> lookupRecords = new List<SObject>();
    // Parent ๊ด€๋ จ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
    if(param.gets('parent')<>null && !param.gets('parent').isEmpty()) {
        parentRecord = param.gets('parent')[0];
    }
    // Lookup ๊ด€๋ จ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
    if(param.gets('lookup')<>null && !param.gets('lookup').isEmpty()) {
        listLookupParameters = param.gets('lookup');
    }
    ...
}

Line-Item Configurator๋กœ ๊ฒฐ๊ณผ๊ฐ’์„ ์ „๋‹ฌํ•˜๊ธฐ ์œ„ํ•ด ์•„๋ž˜ ํด๋ž˜์Šค๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.

SBLD.DataSourceServiceAction Class

๋Œ€์ƒ(Lookup ๋˜๋Š” Line-Item)์˜ ํ–‰๋งˆ๋‹ค Action์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. Action์€ ๋ฐ์ดํ„ฐ์†Œ์Šค ๊ฐ’์„ Lookup ๋˜๋Š” Line-Item ํ•„๋“œ์— ๋งคํ•‘ํ•˜๋Š” ์ž‘์—…์ž…๋‹ˆ๋‹ค.

  • setKeyValue(Object keyValue) Lookup ๋˜๋Š” Line-Item์˜ ๋Œ€์ƒ ๋ ˆ์ฝ”๋“œ๋ฅผ ์ฐพ๊ธฐ ์œ„ํ•œ Key๊ฐ’์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

  • putSourceToTargetField(Object sourceValue, String targetField) ๋ฐ์ดํ„ฐ์†Œ์Šค ๊ฐ’์„ Lookup ๋˜๋Š” Line-Item ํ•„๋“œ์— ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.

SBLD.DataSourceService.Result Class

๋งคํ•‘์ด ์™„๋ฃŒ๋œ Action์„ ๋ฆฌํ„ด ๊ฐ’์— ์ถ”๊ฐ€ํ•˜๋Š” ์ž‘์—…์ž…๋‹ˆ๋‹ค.

  • addAction(SBLD.DataSourceServiceAction action) SBLD.DataSourceService.Result ์ธ์Šคํ„ด์Šค์— Action์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

...
SBLD.DataSourceService.Result result = new SBLD.DataSourceService.Result();
for(Object objResponse : listResponses) {
    Map<String, Object> mapResponse = (Map<String, Object>)objResponse;

    SBLD.DataSourceServiceAction action = new SBLD.DataSourceServiceAction();
    // ๋ฐ์ดํ„ฐ์†Œ์Šค์—์„œ ์„ค์ •ํ•œ Key ํ•„๋“œ์— ์•Œ๋งž๋Š” ๊ฐ’
    action.setKeyValue(mapResponse.get('Id')); // Product Code
    // ๋ฐ์ดํ„ฐ์†Œ์Šค์—์„œ ๊ฐ€์ ธ์˜จ ๊ฐ’์„ Lookup ๋˜๋Š” Line-Item ํ•„๋“œ์— ๋„ฃ๊ธฐ
    action.putSourceToTargetField(mapResponse.get('inventory'), 'Inventory__c');
    // SBLD.DataSourceService.Result์— Action์„ ์ถ”๊ฐ€ํ•œ๋‹ค.
    result.addAction(action);
}
return result;

์˜ˆ์‹œ

์ค€๋น„์ค‘์ž…๋‹ˆ๋‹ค.

Last updated