You are here:
Omnistudio Data Mapper Calls From Apex
Starting with Summer’ 25, to call a Data Mapper from Apex, call the ConnectApi.OmniDesignerConnect.executeDataMapper(bundleName, apexInput) Connect API specifying the name of the Data Mapper and the input data that it requires. This API replaces the vlocity_ins.DRGlobal.processObjectsJSON() method. This Connect API removes the dependency on the managed package and provides up to 60% better performance for Data Mapper calls from an Apex class compared to the previous method.
Specify the input as follows:
-
For a JSON object, use
Map<String, Object>. Set the String to the JSON key and the Object to the JSON value. -
For an array of JSON objects, use
List<Map<String, Object>>. Set the String to the JSON key and the Object to the JSON value. -
As an alternative, you can specify the input as a string containing the JSON input required by the Data Mapper.
For details about the methods of the DRGlobal class, which offer multiple ways to call Data Mappers, see DRGlobal Class and Methods.
Data Mapper Extract or Transform Example
To process the results returned by a Data Mapper extract or transform in Apex, deserialize
the output to a Map<String, Object> or 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'));
}Data Mapper Load Example
Data Mapper loads return JSON containing data about the Salesforce objects that were created or updated by the operation. To process the results returned by a Data Mapper load, deserialize the output to a map. From the resulting map, you can extract data about the objects that were created and any errors that occurred. The Data Mapper load example below shows how to access this data from the result map.
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 errorsData Mapper Load Example with the bulkUpload Parameter
This example code passes the bulkUpload parameter to a Data Mapper Load.
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'));

