an amateur apex user here and I have a question which I've tried to distill below as much as I can. I have a class OrderTriggerHandlerV2 which fires when Order.OriginalContractedOrder__c gets filled in.

I build three maps to get all the data I need to use to build out the rest of the logic:

public class OrderTriggerHandlerV2 {
    public static void updatedAmendmentOrderProducts(Map<Id, Order> updatedOrderMap) {

        List<Order> gatherAmendmentOrderInfo = [SELECT Id, OriginalContractedOrder__c, EffectiveDate, (SELECT Id, Order.EffectiveDate, ServiceDate, EndDate, Original_Segment_Start_Date__c FROM OrderItems WHERE SBQQ__ChargeType__c = 'Recurring Fixed')
                                                FROM Order
                                                WHERE Id IN:updatedOrderMap.keySet()];

        Map<Id, Date> amendmentOrderWithEffectiveDate = new Map<Id, Date>();
        Map<Id, List<OrderItem>> amendmentOrderWithRecurringOrderProducts = new Map<Id, List<OrderItem>>();
        Map<Id, Id> amendmentOrderWIthOriginalOrder = new Map<Id, Id>();

        for(Order a: gatherAmendmentOrderInfo){
            amendmentOrderWithEffectiveDate.put(a.Id, a.EffectiveDate);
            amendmentOrderWithRecurringOrderProducts.put(a.Id, a.OrderItems);
            amendmentOrderWIthOriginalOrder.put(a.Id, a.OriginalContractedOrder__c);

        System.debug('amendmentOrderWithEffectiveDate: '+amendmentOrderWithEffectiveDate);
        System.debug('amendmentOrderWithRecurringOrderProducts: '+amendmentOrderWithRecurringOrderProducts);
        System.debug('amendmentOrderWIthOriginalOrder: '+amendmentOrderWIthOriginalOrder);

When I physically fill in the field which fires the trigger in the sandbox, all the maps get filled:

enter image description here

But when I run my test class, I think I'm missing something as the child OrderItems don't seem to be being picked up. I'm very confused about this and would appreciate any insight into this or approaches I could take to troubleshoot. Thank you @cropredy for answering my post yesterday where I broached almost a similar question. The suggested hypothesis was that I was running into the SFDC test context limitation as it was a queueable class previously. I have changed it to be synchronous and still am hitting the same issue. I have since deleted my previous question to try see if I can get any other insight and so that there isn't a duplication with this - let me know if this goes against any guidelines.

enter image description here

Here is some additional information:


trigger OrderTrigger on Order (before update, after update) {

            // OriginalContractedOrder__c gets filled in
            Map<Id, Order> mapOfOrderswhereOriginalContractedOrderChanges = new Map<Id, Order>();
            for(Order newOrder: Trigger.New){
                Order oldOrder = Trigger.OldMap.get(newOrder.Id);
                if((newOrder.OriginalContractedOrder__c!= oldOrder.OriginalContractedOrder__c)&&(newOrder.OriginalContractedOrder__c!=NULL)){
                    mapOfOrderswhereOriginalContractedOrderChanges.put(newOrder.Id, newOrder);

Test Class

public class OrderTriggerHandlerV2Test {
 @isTest public static void updatedAmendmentOrderProductsTest(){
        // create data
        Account testAcc = testDataFactory.accountCreator('testAcc');

        product2 testProd = testDataFactory.productCreator();

        Order order1 = testDataFactory.orderCreator4FFAmendment(testAcc, 'Draft', Date.newInstance(2020,01,01), 'New');
        insert order1;

        Order order2 = testDataFactory.orderCreator4FFAmendment(testAcc, 'Draft', Date.newInstance(2021,01,01), 'Amendment');
        insert order2;

        OrderItem orderItem4OrderOne = testDataFactory.orderItemCreator4FFAmendment(order1, testProd, Date.newInstance(2020,01,01), Date.newInstance(2022,12,31), 'Annual');
        insert orderItem4OrderOne;

        OrderItem orderItem4OrderTwo = testDataFactory.orderItemCreator4FFAmendment(order2, testProd, Date.newInstance(2021,01,01), Date.newInstance(2022,12,31), 'Annual');
        insert orderItem4OrderTwo;

        Order order2Update = [SELECT Id, OriginalContractedOrder__r.Id, EffectiveDate, 
                             (SELECT Id, Order.EffectiveDate, ServiceDate, EndDate, Original_Segment_Start_Date__c FROM OrderItems)
                             FROM Order
                             WHERE Id =:order2.Id];

        order2Update.OriginalContractedOrder__c = order1.Id;
        system.debug('order2Update:' + order2Update);

        // run test

        update order2Update;


TestDataFactory Class

public static Account accountCreator(string name){
    Account myAccount = new Account();
    myAccount.Name = name;
    insert myAccount;
    return myAccount;

public static product2 productCreator(){
    // 12 Month Subscription Product
    product2 testProd = new product2();
    testProd.Name = 'Test Product';
    testProd.isActive = True;
    testProd.SBQQ__SubscriptionPricing__c = 'Fixed Price';
    testProd.SBQQ__SubscriptionTerm__c = 12;
    testProd.SBQQ__SubscriptionType__c = 'Renewable';
    testProd.ProductCode = 'TST1';
    testProd.SBQQ__PricingMethod__c = 'List';
    testProd.QLE_Product_Group__c = 'CMBS';
    insert testProd;
    // Create Price book entry
    PricebookEntry testPBE = new PricebookEntry();
    testPBE.isActive = TRUE;
    testPBE.Product2Id = testProd.Id;
    testPBE.Pricebook2Id = test.getStandardPricebookId();
    testPBE.UnitPrice = 1000.00;
    insert testPBE;
    return testProd;

public static Order orderCreator4FFAmendment(Account a, String status, Date startDate, String orderType){
    Order newOrder = new Order();
    newOrder.AccountId = a.Id;
    newOrder.Status = status;
    newOrder.EffectiveDate = startDate;
    newOrder.Type = orderType;
    newOrder.Pricebook2Id = test.getStandardPricebookId();
    newOrder.SBQQ__ContractingMethod__c = 'Single Contract';
    newOrder.OriginalContractedOrder__c = NULL;

    return newOrder;

public static OrderItem orderItemCreator4FFAmendment(Order ord, Product2 p, Date startDate, Date endDate, String billingFrequency){
    OrderItem b = new OrderItem();
    b.OrderId = ord.Id;
    b.Product2Id = p.Id;
    b.Quantity = 1;
    b.SBQQ__BillingFrequency__c = billingFrequency;
    b.ListPrice = 1000;
    b.UnitPrice = 1000;
    PricebookEntry a = [SELECT Id
                            FROM PricebookEntry
                            WHERE Product2Id =: p.Id];
    b.PricebookEntryId = a.Id;
    b.ServiceDate = startDate;
    b.EndDate = endDate;
    b.SBQQ__ChargeType__c = 'Recurring Fixed';
    b.SBQQ__SubscriptionPricing__c = 'Fixed Price';
    b.SBQQ__ProductSubscriptionType__c = 'Renewable';
    b.Original_Segment_Start_Date__c = NULL;

    return b;

Wanted to put in an answer here that now seems very simple.

Essentially my subquery, wasn't picking up the OrderItem because there was a process builder I wasn't aware of that was updating the value of OrderItem.SBQQ__ChargeType__c.

SELECT Id, Order.EffectiveDate, ServiceDate, EndDate, Original_Segment_Start_Date__c FROM OrderItems WHERE SBQQ__ChargeType__c = 'Recurring Fixed'

The product lookup was feeding the OrderItem SBQQ__ChargeType__c field value via this process builder and I believe due to the process of operations, after my insert of the order item in my test class, the process builder was firing and overriding it with a null value which resulted in my test class not picking up the OrderItems as SBQQ__ChartType__c = NULL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.