위치:
Omnistudio 데이터 매퍼 호출 Apex
Summer '25부터 Apex에서 데이터 매퍼를 호출하려면 Data Mapper의 이름과 필요한 입력 데이터를 지정하는 ConnectApi.OmniDesignerConnect.executeDataMapper(bundleName, apexInput) Connect API를 호출합니다. 이 API는 vlocity_ins.DRGlobal.processObjectsJSON() 메서드를 대체합니다. 이 Connect API는 관리 패키지에 대한 종속성을 제거하고 이전 방법 대비 Apex 클래스에서 Data Mapper 호출을 최대 60% 향상합니다.
다음과 같이 입력을 지정합니다.
-
JSON 개체의 경우
Map<String, Object>를 사용합니다. 문자열을 JSON 키로 설정하고 개체를 JSON 값으로 설정합니다. -
JSON 개체의 배열의 경우
List<Map<String, Object>>를 사용합니다. 문자열을 JSON 키로 설정하고 개체를 JSON 값으로 설정합니다. -
대신 데이터 매퍼에 필요한 JSON 입력을 포함하는 문자열로 입력을 지정할 수 있습니다.
데이터 매퍼를 호출하는 여러 방법을 제공하는 DRGlobal 클래스의 방법에 대한 자세한 내용은 DRGlobal 클래스 및 방법을 참조하십시오.
데이터 매퍼 추출 또는 변환 예제
Apex에서 Data Mapper 추출 또는 변환을 통해 반환된 결과를 처리하려면 출력을 Map<String, Object> 또는 List<Map<String,
Object>>로 직렬 해제합니다.
/* Specify Data Mapper extract or transform to call */
String bundleName = 'DataMapperName';
/* Populate the input JSON */
Map<String, Object> objectList = new Map<String, Object>{'MyKey'=>'MyValue'};
/* Call the Data Mapper */
String jsonString = JSON.serialize(objectList);
List<String> jsonInputData = new List<String>();
jsonInputData.add(jsonString);
ConnectApi.DataMapperExecuteInputRepresentation apexInput = new ConnectApi.DataMapperExecuteInputRepresentation();
apexInput.dataMapperInput = jsonInputData;
apexInput.inputType = 'JSON';
ConnectApi.DataMapperExecuteOptionsRepresentation options = new ConnectApi.DataMapperExecuteOptionsRepresentation();
options.locale = null;
options.shouldSendLegacyResponse = true;
apexInput.options = options;
ConnectApi.DataMapperExecuteOutputRepresentation output = ConnectApi.OmniDesignerConnect.executeDataMapper(bundleName, apexInput);
/* Process the results returned by a Data Mapper Extract or Transform */
List<String> innerResponse = output.response;
for (String currentResponse : innerResponse){
Map<String, Object> outerMap = (Map<String, Object>) JSON.deserializeUntyped(currentResponse);
List<String> keys = new List<String>(outerMap.keySet());
System.debug(outerMap.get('response'));
}데이터 매퍼 로드 예제
데이터 매퍼를 로드하면 작업을 통해 생성되거나 업데이트된 Salesforce 개체에 대한 데이터가 포함된 JSON이 반환됩니다. 데이터 매퍼 로드에서 반환된 결과를 처리하려면 출력을 맵에 직렬화 해제합니다. 결과 맵에서 생성된 개체 및 발생한 오류에 대한 데이터를 추출할 수 있습니다. 아래의 데이터 매퍼 로드 예는 결과 맵에서 이 데이터에 액세스하는 방법을 보여줍니다.
String objectList = '{"accountName":"Vlocity", "contractCode":"SKS9181"}';
List<String> jsonInputData = new List<String>();
jsonInputData.add(objectList);
ConnectApi.DataMapperExecuteInputRepresentation apexInput = new ConnectApi.DataMapperExecuteInputRepresentation();
apexInput.dataMapperInput = jsonInputData;
apexInput.inputType = 'JSON';
ConnectApi.DataMapperExecuteOptionsRepresentation options = new ConnectApi.DataMapperExecuteOptionsRepresentation();
options.ignoreCache = false;
options.shouldSendLegacyResponse = true;
apexInput.options = options;
ConnectApi.DataMapperExecuteOutputRepresentation output =ConnectApi.OmniDesignerConnect.executeDataMapper(bundleName, apexInput);
List<String> innerResponse = output.response;
String currentResponse = innerResponse[0];
System.debug(currentResponse);
Map<String, Object> outerMap = (Map<String, Object>) JSON.deserializeUntyped(currentResponse);
List<String> keys = new List<String>(outerMap.keySet());
System.debug(outerMap.get('drSObjectResults'));
/*
Process the results of the load: these methods return details about objects affected by the Data Mapper Load, in addition to any errors that occured
*/
Map<String, Object> createdObjectsByType = (Map<String, Object>)resultMap.get('createdObjectsByType');
Map<String, Object> createdObjectsByTypeForBundle = (Map<String, Object>)createdObjectsByType.get('bundleName');
Map<String, Object> createdObjectsByOrder = (Map<String, Object>)resultMap.get('createdObjectsByOrder');
Map<String, Object> errors = (Map<String, Object>)resultMap.get('errors');
Map<String, Object> errorsByField = (Map<String, Object>)resultMap.get('errorsByField');
List<Object> errorsAsJson = (List<Object>)outerMap.get('errorsAsJson'); // Returns input JSON plus per-node errorsbulkUpload 매개 변수가 있는 데이터 매퍼 로드 예제
이 예제 코드는 bulkUpload 매개 변수를 Data Mapper 로드에 전달합니다.
String objectList = '[{"ProductCode__c": 11050665},{"ProductCode__c": 11070100}]'; // replace this with the input for your Data Mapper Load
String bundleName = 'DRLoadPrice'; // replace this with your Data Mapper name
Map<String,Object> bodyData = new Map<String,Object>();
bodyData.put('bundleName',bundleName);
bodyData.put('objectList',objectList);
List<String> jsonInputData = new List<String>();
jsonInputData.add(bodyData.get('objectList'));
ConnectApi.DataMapperExecuteInputRepresentation apexInput = new ConnectApi.DataMapperExecuteInputRepresentation();
apexInput.dataMapperInput = jsonInputData;
apexInput.inputType = 'JSON';
ConnectApi.DataMapperExecuteOptionsRepresentation options = new ConnectApi.DataMapperExecuteOptionsRepresentation();
options.ignoreCache = false;
apexInput.options = options;
options.shouldSendLegacyResponse = true;
ConnectApi.DataMapperExecuteOutputRepresentation output = ConnectApi.OmniDesignerConnect.executeDataMapper(bodyData.get('bundleName'), apexInput);
List<String> innerResponse = output.response;
Map<String, Object> outerMap = (Map<String, Object>) JSON.deserializeUntyped(innerResponse[0]);
List<String> keys = new List<String>(outerMap.keySet());
System.debug(outerMap.get('drSObjectResults'));
