Implementation

Estimated reading: 3 minutes 5 views

Introduction

The Data Map engine is fully handled by the DataMapEngine Apex Class. If you want to apply a map to a specific data structure you’ll need to invoke any of the applyMap methods documented later at this document.

Data Map Variables

It’s possible to use variables in the Data Map. With variables, you can set values to target fields that don’t come directly from the source record/level.

To use the variable value as the Target Field value you just need to prepend the variableName with the dollar ($) sign.
$variableName

There are two ways to set the variable values:

Data Map Attribute

In the Data Map Attribute you can set the variable name in the Variable Name field. The value of the Source Field will be set in the variable. Keep in mind that the Datamap is processed from top to bottom, so you can only use the variable in Data Map Attributes that are below the one that sets the variable.

Programmatically

These variables can be passed as a Map<String, Object> to the applyMap method. This way you can use the variable in any Data Map Attribute without any order restriction.

Reverse Datamap

It’s also possible to execute a Data Map in reverse mode. This means that the data map will be applied using the Target as Source, and the Source as Target. This way you don’t need to duplicate and maintain similar data maps.

To execute it, you must pass the true value as third parameter to the ApplyMap method.

    DataMapEngine.applyMap(Id dataMapId, Map<String, Object> source, true);

Special Cases

Do not map Root Element

Sometime you don’t want to map the root element of the Source Object into the Target, for instance, when generating the Assets from an Order, the Order is not map into the target structure, as we only want the Order Items to be converted into Assets.

In this case, it’s enough by leaving the Target Object and Target Relationship in blank for the Root Object.

ApplyMap Methods

    // By Datamap Name
    DataMapEngine.applyMap(String dataMapName, Map<String, Object> source);
    DataMapEngine.applyMap(String dataMapName, Map<String, Object> source, Map<String, Object> vars);
    DataMapEngine.applyMap(String dataMapName, Map<String, Object> source, boolean reverse);
    DataMapEngine.applyMap(String dataMapName, Map<String, Object> source, Map<String, Object> vars, boolean reverse);

    //By Datamap Id
    DataMapEngine.applyMap(Id dataMapId, Map<String, Object> source);
    DataMapEngine.applyMap(Id dataMapId, Map<String, Object> source, Map<String, Object> vars);
    DataMapEngine.applyMap(Id dataMapId, Map<String, Object> source, boolean reverse);
    DataMapEngine.applyMap(Id dataMapId, Map<String, Object> source, Map<String, Object> vars, boolean reverse);

Parameters

Parameter Type Required Description
dataMapName String Y The name of the Data Map to be applied
dataMapId Id Y The Id of the Data Map to be applied
source Map<String, Object> Y The source structure. It can be custom Map<String, Object> or a SObject Map generated from an Object Tree.
vars Map<String, Object> N A Map with the variables to be used in the Data Map execution.
reverse Boolean N If true, the Data Map will be applied in reverse mode.

Leave a Comment

       
Euphoria, forever till the end of times

Euphoria

Share this Doc

Implementation

Or copy link

CONTENTS