You are here:
ObjectCopierInterface
Initiate creating or updating the header record and its child items in the quote process.
ObjectCopierInterface supports the following scenarios:
-
Creating a quote and its line items from an opportunity and its line items
-
Creating an order and its line items from a quote and its line items
-
Updating an account and its assets from an order and its line items
-
Synchronizing a quote and its line items with an existing opportunity
ObjectCopierInterface operates dynamically on multiple objects for multiple purposes. You typically will not need to customize or modify the standard ObjectCopierInterface functionality.
Triggered When
The ObjectCopierInterface is triggered when creating a quote from an opportunity, an order from a quote, or an asset from an Order. It is also triggered when synchronizing a quote with an opportunity.
Called In
When Vlocity Cart, Opportunity Manager, Order Manager, or Quote Manager initiates any of the triggering events, ConfigurePriceQuoteEventHandler calls the ObjectCopierInterface.
Default Implementation
The DefaultObjectCopierImplementation copies over objects and their children. The input is a parentItemId and an action that must be taken on the parentItemId. It returns an ObjectCopier object that has the newObjectId and the status of the copy.
Other Implementations
None
Input Parameters
parentItemId
Required
Type: Id
The ID of the parent item to clone
action
Required
Type: String
The action to perform or the string can be empty
When calling ObjectCopierInterface to sync a quote to an opportunity, the value of action parameter must be SyncToQuote.
Sample Implementation
The following code does not include a namespace. You must change any referenced package component to refer to the appropriate namespace.
global with sharing virtual class SampleObjectCopierImplementation implements GlobalInterfaces.ObjectCopierInterface {
global ObjectCopier copyObject(Id parentItemId, String action) {
SobjectType parentObjectType = parentItemId.getSObjectType();
Sobject parentItem = getParentItem(parentObjectType, parentItemId);
try {
if (parentObjectType == Opportunity.SObjectType) {
//Create header object
Quote quote = new Quote();
quote.name = (String) parentItem.get('Name');
quote.OpportunityId = (Id) parentItem.get('Id');
quote.Pricebook2Id = (Id) parentItem.get('Pricebook2Id');
upsert quote;
//Add code to clone the line items
ObjectCopier objectCopierInstance = new ObjectCopier();
objectCopierInstance.NewObjectId = new PageReference('/' + quote.Id).getURL();
return objectCopierInstance;
} else if (parentObjectType == Quote.SObjectType) {
//Replicate desired behavior
} else if (parentObjectType == Order.SObjectType) {
}
} catch (Exception e) {
ObjectCopier objectCopierInstance = new ObjectCopier();
objectCopierInstance.NewObjectId = '';
objectCopierInstance.Status = e.getMessage();
return objectCopierInstance;
}
}
private SObject getParentItem(SobjectTyoe objectType, Id objectId) {
String query = 'Select ' + String.join(new List<String> (objectType.getDescribe().fields.getMap().keyset()), ',');
query += ' FROM ' + objectType;
query += ' WHERE Id = :objectId';
query += ' LIMIT 1';
return Database.query(query);
}
}
