1

I wrote a OpportunityLineItem trigger that works with the OpportunityLineItemSchedule items related to it. Now I want to write unit tests for this trigger, and want to use sfdx to push the code to a scratch org to test things.

However, sfdx force:source:push fails on this (simplified) code:

@isTest
private class OpportunityLineItemTest {
    @isTest static void test() {
        OpportunityLineItemSchedule schedule = new OpportunityLineItemSchedule();
    }
}

with the error:

Invalid type: OpportunityLineItemSchedule

How do I create a unit test for OpportunityLineItem objects that use OpportunityLineItemSchedule objects? Do I need to enable a certain feature in the project-scratch-def.json to be able to use these objects?

2 Answers 2

3

We plan to deprecate support for org preferences in Winter ’20. [see here]

As original answer uses them, and they don't convert 1:1 to settings, I am leaving this here for future reference:

{
  "orgName": "Demo Company",
  "edition": "Developer",
  "country": "US",
  "language": "en_US",
  "features": ["ProductsAndSchedules"],
  "settings": {
    "orgPreferenceSettings": {
      "s1DesktopEnabled": true
    },
    "productSettings": {
      "enableQuantitySchedule": true,
      "enableRevenueSchedule": true
    }
  }
}
5

You have to enable a Product schedule feature in the project-scratch-def.json, e.g. like this:

{
  "country": "US",
  "edition": "Developer",
  "features": [],
  "orgPreferences": {
    "enabled": [
      "S1DesktopEnabled",
      "IsRevenueScheduleEnabled"
    ],
    "disabled": []
  },
  "orgName": "My Org",
  "adminEmail": "[email protected]"
}

Once you create the scratch org with IsRevenueScheduleEnabled enabled, the type OpportunityLineItemSchedule will be available in unit tests.

1
  • My bad, i thought OpportunityLineItemSchedule is triggername Nov 18, 2018 at 21:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .