You need to sign in to do that
Don't have an account?

Auto generate opportunity line items
Has anyone auto generated opportunity line items from a custom field in Opportunity.
Ex. Custom Field in Opportunity is linearfeet__c ; want to automatically insert 5 different product line items that are standard and use linearfeet__c in the quantity calculation?
I am working off of http://blog.jeffdouglas.com/2009/02/13/enhancing-the-lead-convert-process-in-salesforce/ as a starting point but lost.
Any help would greatly be appreciated.
Matt
Are you having problems with a particular part of this, or just general trouble getting started?
What I tried to do so far is;
trigger OpportunityPLIStandard Add on Opportunity (after update) {
// ChuteLinearFeet__c is defaulted to 0
if (Opportuntiy.ChuteLinearFeet=0) {
// add an opportunity line item
OpportunityLineItem oli = new OpportunityLineItem();
oli.OpportunityId = opp.Id;
oli.Quantity = Opportunity.ChuteLinearFeet__C;
oli.PricebookEntryId = [Select p.Id From PricebookEntry p Where PricebookEntry.Product2.Name = '24" Standard Chute' And IsActive = true limit 1].Id;
insert oli;
An apex trigger is much like a database trigger - its a section of code that exists in isolation and gets invoked in response to something happening to one or more records.
In your case, the trigger will only be executed when an opportunity is updated, rather than when it is inserted - is that what you are looking for?
Also, this trigger will have an affect each time the opportunity is updated, so you'd add a product each time. You might want to check if there are any products associated with the opportunity before adding one, or setting a flag on the record to indicate that the autogenerated product has been added.
Did you ever find a solution to this. I'd love to know how you accomplished it. Thanks in advance for your response.