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?

up vote 4 down vote accepted

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": "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 at 21:31

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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