0

I have an issue with unit testing a piece of logic built for Evergreen Subscriptions. When trying to insert Evergreen product I get following:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Can't save Product. Evergreen Subscriptions are not enabled.: []

Evergreen Subscriptions are enabled in managed package (v. 220.10) configuration. Evergreens are working normally and even the same code fired in dev console runs without such issues.

Here is the piece of logic causing issues:

this.products = new List<Product2>{
    new Product2(
        Name = 'Test',
        IsActive = true,
        Family = 'License', 
        PricingCycle__c = 'Monthly',
        SBQQ__SubscriptionType__c = isEvergreen ? 'Evergreen' : 'Renewable'
    )
};
insert this.products;
  • If CPQ manages Evergreen Subscription settings in a Custom Setting, then your test class will need to mock this as custom settings have no values in testmethods (unless you use seeAllData=true which I heartily don't recommend) – cropredy Jul 12 at 2:11
  • thanks for your comment. I don't think CPQ stores configuration in any publicly accessible custom setting – neff Jul 12 at 21:40
0

I managed to make it work by disabling CPQ Triggers as below:

this.products = new List<Product2>{
    new Product2(
        Name = 'Test',
        IsActive = true,
        Family = 'License', 
        PricingCycle__c = 'Monthly',
        SBQQ__SubscriptionType__c = isEvergreen ? 'Evergreen' : 'Renewable'
    )
};
SBQQ.TriggerControl.disable();
insert this.products;
SBQQ.TriggerControl.enable();

Not sure if that's the best way, though. If you have a better idea please post your answer.

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.