I am working on a test class for an org that uses Salesforce CPQ, and I need to test a class that checks the SBQQ__SubscriptionType__c field on OrderItems for Evergreen subscriptions.

The problem is that my test class can't see that the org settings allowing Evergreen products are turned on, so it doesn't allow me to insert Products with a subscription type of Evergreen.

Normally, I would just disable the CPQ triggers with SBQQ.TriggerControl.disable() and insert them anyway, but the only way for OrderItems to get the SBQQ__SubscriptionType__c field filled out is with those triggers on (you can't write to the field manually).

So I am in a bit of a Catch-22 where I can't insert Evergreen subscription products with triggers on, but I can't get OrderItems with Subscription Types with the triggers off.

Since Salesforce CPQ is a managed package, I'm not sure I can make a mock setting configuration for the test class that tells it to allow Evergreen products. Does anyone have any idea how to get past this? I am copying my code below, but it uses a pretty kitted out test factory so you won't be able to see everything going on under the hood.

    static void createData(){
        Map<String, Id> billingMap = OSCPQ_TestFactory.createBillingIdMap();
        Id pbId = billingMap.get('priceBook');
        Id brId = billingMap.get('billingRule');
        Id revenueRecognitionRule = billingMap.get('rrr');
        Id taxRule = billingMap.get('taxRule');
        Id pgId = billingMap.get('pg');
// Note that setupMap below is creating an account, an order, a variation parent product, a variation product, and an orderItem linked to all of those things correctly. It inserts the products with SBQQ.TriggerControl.disable() on.
        Map<String, Id> setupMap = OSCPQ_TestFactory.createSetupMap('Renewable', billingMap, false, true);
        Id orderId = setupMap.get('order');
        Id acctId = setupMap.get('account');
// Note this setupMap works the same as before but instead of creating its own order and account, it uses the existing one from the previous setupMap
        OSCPQ_TestFactory.createSetupMap('Evergreen', billingMap, false, false, orderId, acctId);
        List<OrderItem> testOis = [SELECT Id, SBQQ__SubscriptionType__c FROM OrderItem];
        Order o = [Select Id, Status FROM Order Limit 1];
        o.status = 'Activated';
        update o;



You must log in to answer this question.

Browse other questions tagged .