You need to sign in to do that
Don't have an account?
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:
Hi Ryanh,
did you get some answers in the meanwhile - i'm facing some schedule-testing too and wondere ...
Regards, Johannes
Was there ever any update on this item?
do you need do create a schedule for a testclass only?
I need it to happen for real products, not test methods.
please tell where you can't go further. post your code.
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.
then i cannot help right now :( but will take a look later
I have the same problem ? Any news ? Did someone logged a case ?
nope -but it would be a good idea. as i don't need it really anymore i won't be the one ;)