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:

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?


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

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": [
    "disabled": []
  "orgName": "My Org",
  "adminEmail": "admin@my.org"

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

  • My bad, i thought OpportunityLineItemSchedule is triggername – Pranay Jaiswal Nov 18 '18 at 21:31

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.