function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RyanhRyanh 

Revenue schedule not created by default through Apex

If you create a Product (Product2), enable scheduling and define a default revenue schedule, when you add that product to an Opportunity, a schedule will be created.

 

For instance, if my default revenue schedule is defined as:

  • Revenue schedule type = Repeat Amount for each installment
  • Revenue Installment Period = monthly
  • Number Of Revenue Installments = 12

And then I add this product to an opportunity with a quantity of 1 and a price of $500, I'll see 12 schedule entries (OpportunityLineItemSchedule records), $500 each, and occurring every month.

If I add this same product to an opportunity through Apex and specify quantity=1 and price=500, the product (OpportunityLineItem) will be added, but no schedule entries will be created.

 

Here's my code:

 

Product2 search_product = [select Id from Product2 where ProductCode='Budget_T1_LP_Call_Proxy']; Pricebook2 pricebook = [SELECT Id, Name FROM Pricebook2 WHERE isStandard=true AND isDeleted=false AND isActive=true]; PricebookEntry pbentry=null; try { pbentry = [select Id from PricebookEntry where Pricebook2Id=:pricebook.Id and Product2Id=:search_product.Id and isActive=true and UnitPrice=0 and UseStandardPrice=false]; } catch (System.Queryexception e) { pbentry = new PricebookEntry(Pricebook2Id=pricebook.Id,Product2Id=search_product.Id,isActive=true,UnitPrice=0,UseStandardPrice=false); insert pbentry; } OpportunityLineItem opp_product = new OpportunityLineItem(OpportunityId=io.Opportunity__c,PriceBookEntryId=pbentry.Id,Quantity=1, UnitPrice=io.monthly_budget__c, ServiceDate=io.Monthly_budget_bill_date__c ); insert opp_product;

 

My guess is that Salesforce wrote code to create the schedule outside of the standard controller and it is not executed when you simply add the product through Apex.

 

Thoughts? Can anyone confirm this?

 

 

For some background, see these posts:

  1. Revenue scheduling unit test not working
  2. Can't test product scheduling
JohannesBorrmanJohannesBorrman

Hi Ryanh,

 

did you get some answers in the meanwhile - i'm facing some schedule-testing too and wondere ...

 

Regards, Johannes

coder312Astadiacoder312Astadia
PLEASE  HELP!  - I'm having this exact problem and need to know how to resolve it.  Has anyone from Salesforce.com responded to this question???
kpetersonkpeterson

Was there ever any update on this item?

JohannesBorrmanJohannesBorrman

do you need do create a schedule for a testclass only?

kpetersonkpeterson

I need it to happen for real products, not test methods.

JohannesBorrmanJohannesBorrman

please tell where you can't go further. post your code.

kpetersonkpeterson

My issue is the exact same as the original poster, inserting opportunity line items for products that have default revenue schedules does not create the revenue schedules.

JohannesBorrmanJohannesBorrman

then i cannot help right now :(  but will take a look later

bennyfajbennyfaj

I have the same problem ? Any news ? Did someone logged a case ?

JohannesBorrmanJohannesBorrman

nope -but it would be a good idea. as i don't need it really anymore  i won't be the one ;)

Mitesh SuraMitesh Sura
Has anyone found a solution? I see there are schedule fields on line item, but they are read only.