+ Start a Discussion
Mitesh SuraMitesh Sura 

Create OpportunityLineItemSchedule records automatically

I am building custom VF page for "Add Products". For most part it works fine, but it does create "OpportunityLineItemSchedule" records like standard "Add Products" screen.

What am I missing? Is there a way to set certain parameters to parent OpportunityLineItem object to achieve this? I found few examples on creating "OpportunityLineItemSchedule" records manually, but I would like to avoid that if Salesforce can do that automatically for me.

Thank you for your time.

regards
Mitesh
Best Answer chosen by Mitesh Sura
Mitesh SuraMitesh Sura
For those who are keeping score, "In API version 38.0 and later, when an OpportunityLineItem record is created for a product with a previously established schedule, an OpportunityLineItemSchedule record is also created." 

This means no need of custom logic to create Schdule Line Items, it will happen automatically when creating line items. 

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_opportunitylineitemschedule.htm

All Answers

Ashish_SFDCAshish_SFDC
Hi Mitesh, 


This is the recursive trigger issue when inserting OpportunityLineItemSchedule records from an after insert trigger on OpportunityLineItem.

By first checking if a static boolean that gets set at the end of the first trigger invocation is true the recursion could be avoided.

There is an example here: Controlling Recursive Triggers

http://developer.force.com/cookbook/recipe/controlling-recursive-triggers


https://developer.salesforce.com/forums/ForumsMain?id=906F000000090HrIAI


Regards,
Ashish
Mitesh SuraMitesh Sura
Thanks Ashish, but I do understand concept of recursive trigger. Probably I will have to do that, if I have to create "OpportunityLineItemSchedule" records manually. 

My question is, do we actually have to create those manually? Why would standard "Add Products" button work, but not custom VF page. Isn't there anyway we can automate the default scheduling? 

regards
Mitesh
Ashish_SFDCAshish_SFDC
Hi Mitesh, 


What Controller are you using, loosk like the Add Products Action Binding is not supported with the Standard Controller. 

You can try instantiating Standard Controller. 

See the related thread,

http://salesforce.stackexchange.com/questions/16843/visualforce-adding-new-products-to-a-table-on-same-page


Regards,
Ashish 
Mitesh SuraMitesh Sura
Thanks Ashish, but I am not sure how can I use Standard Controller for Opportunity Line item object?

here is the link of custom VF page for adding Products. https://na14.visual.force.com/apex/Products_Add?id=006d000000DAv0K.

If you look at the id in the URL. Obviously, I get this error "Id value 006d000000DAv0K is not valid for the OpportunityLineItem standard controller"

I liked the idea of invoking Opportunity Product standard controller on save, not sure how to achieve it though. ANy thoguts?
Ashish_SFDCAshish_SFDC
Hi Mitesh, 


Not exactly sure. but see if the below links help, 

You should look at the Snazzy Product Entry Screen from Michael Farrington. We use this internally and since it's an unmanaged package, you can customize it to your needs. I would think your "quantity" requirement would be easy to add to this.

This essentially replaces the add product page and the multiline edit page. It sounds like it might be exactly what you are looking for.

http://salesforce.stackexchange.com/questions/5581/has-anyone-tried-to-create-custom-add-product-page-and-multilineitem-page-from-o

http://www.michaelforce.org/recipeView?id=a0G30000006eVxVEAU


Regards,
Ashish
Mitesh SuraMitesh Sura
Ashish,

I am NOT looking for help on how to build custom VF page to add products. I GOT that. The links that you posted will not support SChduling too and THAT is what I need help with. 

I actually have figured how it works, and build custom trigger to create scheduling records. I am still struglling on how does SF calcualate Quantity and Revenue if BOTH the default scheduling is turned on for a product. 

Any help on that? 

regards
Mitesh


Ashish_SFDCAshish_SFDC
Hi Mitesh,


See the blog below,

There is code for scheduleBuilder Controller and the method to call,

http://kermoony.wordpress.com/2012/04/09/opportunitylineitems-updates-via-visualforce-vf-in-salesforce-com/


Regards,
Ashish
Mitesh SuraMitesh Sura
Thanks Ashsih. Looking at the controller, I do not think it is going to work. It is redirecting user to Opportunity Schedule page.

I will give it a try anyways.

regards
Mitesh
iKnowSFDCiKnowSFDC
Hi Mitesh,

Were you able to solve this problem? And more importantly, write test code? I'm having issues getting test code written for a trigger that updates the OpportunityLineItemSchedule when the OPportunity Close Date updates. I can't get the product schedules inserted so I can test to make sure they are updating properly. 

Thanks for any feedback!
JoAnn
Ashish_SFDCAshish_SFDC
Hi JoAnn, 


Looks like This issue has been addressed in the below post, 

https://developer.salesforce.com/forums/ForumsMain?id=906F00000009cAaIAI


Regards,
Ashish
Mitesh SuraMitesh Sura
@JoAnn : I am close. I have figures it out for Revenue OR Quantity schedule, but not BOTH. 

@Ashish: that link explans revenue schedule, which I have figured it out. Please see this community link which has more info: https://success.salesforce.com/answers?id=90630000000heJcAAI 

regards
Mitesh


Mitesh SuraMitesh Sura
For those who are keeping score, "In API version 38.0 and later, when an OpportunityLineItem record is created for a product with a previously established schedule, an OpportunityLineItemSchedule record is also created." 

This means no need of custom logic to create Schdule Line Items, it will happen automatically when creating line items. 

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_opportunitylineitemschedule.htm
This was selected as the best answer