Skip to main content
[ This file is autogenerated from apexdoc ]

AqMappingToolService

Main entry point for mapping operations. Provides static methods to convert Salesforce records to JSON and upsert records from JSON based on mapping configuration.

Group modules/mapping tool

Overview​

AqMappingToolService is the primary service class for the Mapping Tool module. It provides high-level static methods for bidirectional data transformation between Salesforce SObjects and JSON.

Key Capabilities​

  • Convert Salesforce records to JSON format based on mapping configuration
  • Upsert Salesforce records from JSON using external IDs for matching
  • Support for hierarchical data structures with parent-child relationships
  • Automatic type conversion and field mapping

See the main module documentation for comprehensive usage examples and configuration details.

Fields​

public AQRESULT_TYPE_PARSING_RESULT → String​


Methods​

public static String mapObjectsToJSON(List<Id> rootObjectIds, ObjectDefinitionMapping__mdt mappingMetadata)​

This method maps a list of root object IDs to a JSON document based on the provided mapping metadata. It retrieves and maps data from the root objects and their related objects at multiple levels.

Parameters​

ParamDescription
rootObjectIdsList of IDs of the root objects to be mapped.
mappingMetadataMetadata defining the mapping for the objects.

Returns​

TypeDescription
StringExample JSON structure:

Precondition - Object Definition created for Account. - Field Definition records created for Account (a list of fields with different data types). - Object Definition created for Mobile Phone (Account related record, lookup). - Field Definition records created for Mobile Phone. - Object Definition created for Phone Model (Mobile Phone related record, master-detail). - Field Definition records created for Phone Model. - Accounts with several opportunities (to test rollup field), associated Mobile Phones and Phone Models created.

Example​

[
{
"Mobile Phones": [
{
"Phone Model": [
{
"MF to attach": "...",
"ExtIdPM": "1",
"MF Model": "Phone Model 1"
},
{
"MF to attach": "...",
"ExtIdPM": "2",
"MF Model": "Phone Model 2"
}
],
"Phone Vendor": "Mobile Phone Name",
"AccountToAttach": "...",
"Ext Id": 321
}
],
"Car Models": [
{
"Close Date": "2022-02-24",
"Stage Name": "Prospecting",
"Model Name": "opp"
}
],
"Picklist": null,
"Checkbox": true,
"Currency": 500.47,
"JSONid": "qwerty2",
"MultiPicklist": "q;w;y",
"Formula": true,
"Opportunities Count": 1,
"Brand": "qwerty2",
"Currency Code": "USD"
}
]

public static String mapObjectsToJSON(List<Id> rootObjectIds, String mappingMetadataName)​

public static String mapObjectsToJSON(List<Id> rootObjectIds, ObjectDefinitionMapping__mdt mappingMetadata, AqSObjectToJSONConverter converter)​

public static String mapObjectsToJSON(List<Id> rootObjectIds, String mappingMetadataName, AqSObjectToJSONConverter converter)​

public static AqResult upsertRecordsFromJson(String jsonString, ObjectDefinitionMapping__mdt mappingMetadata, Boolean requireExternalIds)​

This method updates records based on the provided JSON string. The JSON string should contain the fields to be updated, and the method will use External Ids to match records for updating. Precondition: - Object Definition configured for User object. - Field Definitions created for User object (Last Name is External Id).

Usage - The User record with the specified Last Name should be updated with the new First Name value. - If the update is successful, the debug log should display the Record Id of the updated User record. - If there is an error, the debug log should display the error message.

Example​

String jsonString = '[{"LastName" : "USER LAST NAME", "FirstName" : "NEW VALUE FOR NAME "}]';
AqResult result = AqMappingToolService.upsertRecordsFromJson(jsonString, 'User', true);
if (result.Severity == AqResult.SEVERITY_SUCCESS) {
for (AqRecordWithChildren rec : (List<AqRecordWithChildren>)result.ReturnValue) {
System.debug('Record Id: ' + rec.record.Id);
}
} else {
System.debug('Error message: ' + result.Message);
}

public static AqResult upsertRecordsFromJson(String jsonString, String mappingName, Boolean requireExternalIds)​

public static AqResult upsertRecordsFromJson(String jsonString, String mappingName, Boolean requireExternalIds, AqFieldDefinitionMappingData fieldDefinitionData, AqObjectDefinitionMappingData objectDefinitionData)​