Question
How we can develop and test a salesforce custom mapper ourselves before seeking approval?
-
Create javascript file 'customLogic.js' (The name may be any).
-
Create 'resources' folder in the same directory with
-
Add resources that will be passed to custom logic hook as input parameter. Example create entity.json file and add entity JSON to it
-
In ‘customLogic.js' need to import all resources with using ‘require’ or 'import’ commands.
Example:
const entity = require('./resources/entity.json');
-
Add a function that will have custom logic hook code:
Example:
function tenantRequestModification (reltioObject) { this.logging(`Tenant request modification: entity uri: ${reltioObject.uri}`); const atrributes = Object.keys(entity?.attributes || []); const crosswalkTypes = entity?.crosswalks.map(cw => cw.type); this.logging(`Entity attributes: ${atrributes}`); this.logging(`Entity crosswalks: ${crosswalkTypes}`); return reltioObject; }
-
Add logging function to the context:
this.logging = message => { console.log(message); };
-
Call function and provide ‘this’ as context:
tenantRequestModification.call(this, entity);
-
Execute customLogic.js file.
-
After testing move function content to custom logic file without any change.
Full example of customLogic.js file with tenantRequestModification
hook that receive entity JSON as input parameter. Custom logic example write to console a list of entity attributes and crosswalk types:
const entity = require('./resources/entity.json'); function tenantRequestModification (reltioObject) { this.logging(`Tenant request modification: entity uri: ${reltioObject.uri}`); const atrributes = Object.keys(entity?.attributes || []); const crosswalkTypes = entity?.crosswalks.map(cw => cw.type); this.logging(`Entity attributes: ${atrributes}`); this.logging(`Entity crosswalks: ${crosswalkTypes}`); return reltioObject; } this.logging = message => { console.log(message); }; tenantRequestModification.call(this, entity);
Entity JSON from the resources/entity.json
{ "uri": "entities/04wqwvy", "type": "configuration/entityTypes/HCP", "createdBy": "ebakaev", "createdTime": 1708683981313, "updatedBy": "sfdc.connector.admin", "updatedTime": 1708683997738, "attributes": { "SFDCFlag": [ { "type": "configuration/entityTypes/HCP/attributes/SFDCFlag", "ov": true, "value": "true", "uri": "entities/04wqwvy/attributes/SFDCFlag/a6M8v4s" } ], "FirstName": [ { "type": "configuration/entityTypes/HCP/attributes/FirstName", "ov": true, "value": "Test", "uri": "entities/04wqwvy/attributes/FirstName/a6M8mYM" } ], "LastName": [ { "type": "configuration/entityTypes/HCP/attributes/LastName", "ov": true, "value": "Test", "uri": "entities/04wqwvy/attributes/LastName/a6M8qoc" } ] }, "isFavorite": false, "crosswalks": [ { "uri": "entities/04wqwvy/crosswalks/a6M8zL8", "type": "configuration/sources/Reltio", "value": "04wqwvy", "reltioLoadDate": "2024-02-23T10:26:21.313Z", "createDate": "2024-02-23T10:26:21.313Z", "updateDate": "2024-02-23T10:26:21.313Z", "attributes": [ "entities/04wqwvy/attributes/FirstName/a6M8mYM", "entities/04wqwvy/attributes/SFDCFlag/a6M8v4s", "entities/04wqwvy/attributes/LastName/a6M8qoc" ], "singleAttributeUpdateDates": {} }, { "uri": "entities/04wqwvy/crosswalks/hNGsej7", "type": "configuration/sources/SFDC", "sourceTable": "Account", "value": "0015G00002vdUrOQAU", "reltioLoadDate": "2024-02-23T10:26:37.738Z", "createDate": "2024-02-23T10:26:37.738Z", "updateDate": "2024-02-23T10:26:37.738Z", "attributes": [ "entities/04wqwvy/attributes/FirstName/a6M8mYM", "entities/04wqwvy/attributes/LastName/a6M8qoc" ], "singleAttributeUpdateDates": {} } ], "analyticsAttributes": {}, "label": "Test Test", "secondaryLabel": "" }
Console output:
Tenant request modification: entity uri: entities/04wqwvy Entity attributes: SFDCFlag,FirstName,LastName Entity crosswalks: configuration/sources/Reltio,configuration/sources/SFDC
Comments
Please sign in to leave a comment.