Am having a scenario where Assets is being created using orchestration definition Auto task and assets linked to the billing account of the customer.
In the Asset Trigger,
For afterInsert: Retrieve Network priority, End Customer from OrderItem.vlocity_cmt__JSONAttribute__c and insert to Asset. Network_priority__c, Asset. End_Customer_c respectively
For AfterUpdate: If the Network Prioritization, End Customer Type , Carelevel are same as old values respectively then leave the same else Retrieve Network Prioritization, End Customer Type and Carelevel from OrderItem.vlocity_cmt__JSONAttribute__c and insert to Asset. Network_priority__c, Asset. End_Customer_c respectively
Asset -> Order and Order line item as lookup relationship.
Can you please share the code for this on trigger handler.
Sample Code i created
List<OrderItem> OrderItemswithAssets = [select id,Order.Access_Type__c,ProductCode__c,vlocity_cmt__JSONAttribute__c, vlocity_cmt__Product2Id__r.vlocity_cmt__ObjectTypeId__r.name from OrderItem where id in : orderitemIds];
List<Asset> assetListToInsert = newObjects;
for(OrderItem Oitm:OrderItemswithAssets) {
objecttype= '';
networkPriortisation = '';
endCustomerType = '';
Asset assetToBeInserted = new Asset();
assetListToInsert = new List<Asset>();
system.debug('Order.Access_Type__c ' + Oitm.Order.Access_Type__c);
if(Oitm.Order.Access_Type__c=='SOGEA') {
objecttype = Oitm.vlocity_cmt__Product2Id__r.vlocity_cmt__ObjectTypeId__r.name;
system.debug('order ITem objecttype ' + objecttype);
if (objecttype.contains('TTB Broadband Object')) {
OiUtilAttribute OiAttr = new OiUtilAttribute(Oitm); // To parse JSON
system.debug('JSON Attr' + Oitm.vlocity_cmt__JSONAttribute__c);
networkPriortisation = OiAttr.parseJSONRunTimeAttributes('ATTCAT-TTB-BROADBAND-CH',Oitm.vlocity_cmt__JSONAttribute__c,'ATT-TTWS-NETWORK-PRIORITISATION');
endCustomerType = OiAttr.parseJSONRunTimeAttributes('ATTCAT-TTB-BROADBAND-CH',Oitm.vlocity_cmt__JSONAttribute__c,'ATT-TTWS-END-CUSTOMER-TYPE');
//system.debug('networkPriortisation -->' + networkPriortisation);
//system.debug('endCustomerType -->' + endCustomerType );
assetToBeInserted.NetworkPrioritization__c = networkPriortisation;
assetToBeInserted.End_Customer_Type__c = endCustomerType ;
assetListToInsert.add(assetToBeInserted);
}
}
if (assetListToInsert.size() > 0) {
UPDATE assetListToInsert;
}
}