You are here:
Maintain Advertising Sales Management Object and Field Mapping
When a Quote is converted to an Order, the data from the Quote, Quote Line Item, and Ad Quote Line Items must be copied to the Order, Order Line Item, and Ad Order Item respectively.
This is an Advertising Sales Management on Managed Package feature. For Advertising Sales
Management on Salesforce Platform, see Advertising
Sales Management on Salesforce Platform.
The CPQ Field Map Maintenance and Object jobs insert the mapping for Quote and Quote Line Item. However, to insert the mapping between Ad Quote Line and AD Order Item, you must manually run the following code under Anonymous mode from the Developer Console.
checkAndInsertASMMapper();
private void checkAndInsertASMMapper()
{
checkAndInsertObjectMapper();
checkAndInsertFieldMapper();
}
private void checkAndInsertObjectMapper()
{
List<vlocity_cmt__CustomObjectMap__c> objMapper = [SELECT Id, Name FROM vlocity_cmt__CustomObjectMap__c
WHERE vlocity_cmt__SourceParentObject__c = 'QuoteLineItem'
AND vlocity_cmt__SourceChildObject__c = 'AdQuoteLine' LIMIT 1];
if(objMapper.isEmpty())
{
//For every quote line item, if there is a corresponding ad quote line, then
//create the corresponding ad order item record and map to order item record.
vlocity_cmt__CustomObjectMap__c asmObjMap = new vlocity_cmt__CustomObjectMap__c(
Name = 'SIC_QLI>OI',
vlocity_cmt__SourceParentObject__c = 'QuoteLineItem',
vlocity_cmt__SourceChildObject__c = 'AdQuoteLine',
vlocity_cmt__DestinationParentObject__c = 'OrderItem',
vlocity_cmt__DestinationChildObject__c = 'AdOrderItem',
vlocity_cmt__ParentDestinationReferenceField__c = 'OrderItemId',
vlocity_cmt__ParentSourceReferenceField__c = 'QuoteLineItemId'
);
insert asmObjMap;
System.debug(LoggingLevel.DEBUG,'**** ASM Object Mapper inserted');
}
else
{
System.debug(LoggingLevel.DEBUG,'**** ASM Object Mapper Present');
}
}
private void checkAndInsertFieldMapper()
{
List<vlocity_cmt__CustomFieldMap__c> allFieldMapperList = [SELECT ID, vlocity_cmt__DestinationFieldName__c, vlocity_cmt__DestinationSObjectType__c, vlocity_cmt__SourceFieldName__c, vlocity_cmt__SourceFieldType__c, vlocity_cmt__SourceSObjectType__c FROM vlocity_cmt__CustomFieldMap__c];
Map<String, List<String>> fieldMapperMap = new Map<String, List<String>>();
for(vlocity_cmt__CustomFieldMap__c mapper : allFieldMapperList)
{
if(fieldMapperMap.containsKey(mapper.vlocity_cmt__SourceSObjectType__c))
{
List<String> tmpList = fieldMapperMap.get(mapper.vlocity_cmt__SourceSObjectType__c);
tmpList.add(mapper.vlocity_cmt__SourceFieldName__c +'=>' + mapper.vlocity_cmt__DestinationFieldName__c);
fieldMapperMap.put(mapper.vlocity_cmt__SourceSObjectType__c, tmpList);
}
else
{
fieldMapperMap.put(mapper.vlocity_cmt__SourceSObjectType__c, new List<String>{mapper.vlocity_cmt__SourceFieldName__c +'=>' + mapper.vlocity_cmt__DestinationFieldName__c});
}
}
List<SObject> objList = new List<SObject>();
vlocity_cmt__CustomFieldMap__c record;
if(fieldMapperMap.containsKey('Quote') && !fieldMapperMap.get('Quote').contains('Id=>QuoteId'))
{
//insert Quote.Id to Order.QuoteId mapping
record = new vlocity_cmt__CustomFieldMap__c(
Name = 'SIC_QuoteId>OrderQuoteId',
vlocity_cmt__SourceSObjectType__c = 'Quote',
vlocity_cmt__DestinationSObjectType__c = 'Order',
vlocity_cmt__SourceFieldName__c = 'Id',
vlocity_cmt__DestinationFieldName__c = 'QuoteId',
vlocity_cmt__SourceFieldType__c = 'id',
vlocity_cmt__SourceFieldSObjectType__c = null
);
objList.add(record);
}
if(fieldMapperMap.containsKey('QuoteLineItem') && !fieldMapperMap.get('QuoteLineItem').contains('Id=>QuoteLineItemId'))
{
//insert QuoteLineItemId.Id to OrderItem.QuoteLineItemId mapping
record = new vlocity_cmt__CustomFieldMap__c(
Name = 'SIC_QLIId>OIQLI',
vlocity_cmt__SourceSObjectType__c = 'QuoteLineItem',
vlocity_cmt__DestinationSObjectType__c = 'OrderItem',
vlocity_cmt__SourceFieldName__c = 'Id',
vlocity_cmt__DestinationFieldName__c = 'QuoteLineItemId',
vlocity_cmt__SourceFieldType__c = 'id',
vlocity_cmt__SourceFieldSObjectType__c = null
);
objList.add(record);
}
//insert Ad Quote Line to Ad Order Item mapping
//If any custom fields needs to be included, update the below mappingList with field apiName.
List<String> mappingList = new List<String>{'Name=>Name','MediaType=>MediaType',
'QuoteLineItemId=>QuoteLineItemId','AdRequestedStartDate=>AdRequestedStartDate',
'AdRequestedEndDate=>AdRequestedEndDate','IsAdBleedEnabled=>IsAdBleedEnabled',
'AdBleedAmountUom=>AdBleedAmountUom','AdCreativeUrl=>AdCreativeUrl',
'AdCreativeSizeTypes=>AdCreativeSizeTypes','AdBleedAmount=>AdBleedAmount',
'MaximumFrequency=>MaximumFrequency','MaximumFrequencyInterval=>MaximumFrequencyInterval',
'MaximumUserFrequency=>MaximumUserFrequency','MaximumUserFrequencyInterval=>MaximumUserFrequencyInterval',
'TargetingParameters=>TargetingParameters','UserEngagementGoalType=>UserEngagementGoalType',
'UserEngagementGoalUnit=>UserEngagementGoalUnit','AdPlacementPriorityType=>AdPlacementPriorityType',
'AdSpaceSpecificationId=>AdSpaceSpecificationId','UserEngagementGoalUnitType=>UserEngagementGoalUnitType',
'PaidAdTime=>PaidAdTime','ImpliedTotal=>ImpliedTotal','CustomerDayPart=>CustomerDayPart',
'SponsorshipType=>SponsorshipType','TotalAdTime=>TotalAdTime','GrossRatingPoint=>GrossRatingPoint',
'ImpliedRate=>ImpliedRate','BonusAdTime=>BonusAdTime','CostPerRatingPoint=>CostPerRatingPoint','RequestedIssues=>RequestedIssues',
'ContractedQuantity=>ContractedQuantity','EstimatedQuantity=>EstimatedQuantity','ImpressionLimit=>ImpressionLimit',
'Skippable=>Skippable', 'MaxDuration=>MaxDuration', 'SecondaryCostPerRatingPoint=>SecondaryCostPerRatingPoint',
'SecondaryGrossRatingPoint=>SecondaryGrossRatingPoint', 'PrimaryCostPerMille=>PrimaryCostPerMille', 'SecondaryCostPerMille=>SecondaryCostPerMille',
'PrimaryDemographicCodeId=>PrimaryDemographicCodeId', 'SecondaryDemographicCodeId=>SecondaryDemographicCodeId', 'PrimaryImpressions=>PrimaryImpressions',
'SecondaryImpressions=>SecondaryImpressions','PrimaryRating=>PrimaryRating','SecondaryRating=>SecondaryRating', 'PrimaryTotalImps=>PrimaryTotalImps',
'SecondaryTotalImps=>SecondaryTotalImps','AdRequestedQuantity=>AdRequestedQuantity'
};
List<String> existingMapping = new List<String>();
if(fieldMapperMap.containsKey('AdQuoteLine'))
{
existingMapping = fieldMapperMap.get('AdQuoteLine');
}
Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map <String, Schema.SObjectField> fieldMap = schemaMap.get('AdQuoteLine').getDescribe().fields.getMap();
for(String str : mappingList)
{
if(!existingMapping.contains(str))
{
String srcField = str.substringBefore('=>');
String destField = str.substringAfter('=>');
schema.describefieldresult dfield = fieldMap.get(srcField).getDescribe();
record = new vlocity_cmt__CustomFieldMap__c(
Name = ('SIC_' + srcField + '>' + destField).left(38),
vlocity_cmt__SourceSObjectType__c = 'AdQuoteLine',
vlocity_cmt__DestinationSObjectType__c = 'AdOrderItem',
vlocity_cmt__SourceFieldName__c = srcField,
vlocity_cmt__DestinationFieldName__c = destField,
vlocity_cmt__SourceFieldType__c = String.valueOf(dfield.getType()),
vlocity_cmt__SourceFieldSObjectType__c = dfield.getReferenceTo().isEmpty() ? null : String.valueOf(dfield.getReferenceTo()[0])
);
objList.add(record);
}
}
if(!objList.isEmpty())
{
insert objList;
System.debug(LoggingLevel.DEBUG,'**** ASM Field Mapper inserted');
}
else
{
System.debug(LoggingLevel.DEBUG,'**** ASM Field Mapper Present');
}
}
