0

I would like to copy all related Lead Products from Lead to OpportunityLineItems for the Opportunity when the Lead is converted.

I thought there might be a base Apex class I could extend to additional behaviour to Lead conversion?

4
  • I think What is the best approach to achieve this would fall under the "primarily opinion based" category
    – glls
    Jan 21, 2019 at 18:59
  • 3
    I dont think there is any apex base class or guidelines in this dept. I would write a trigger Jan 21, 2019 at 19:03
  • There is probably a better place to discuss this, but best-practice discussions should not be banned here. Any code has opinions in it, inherently, such as the best type of loop to use. Best approach questions are very instructive. For example, workflow vs trigger has some pretty deep considerations. Please stop flagging as opinion-based. Maybe we need to open a thread in meta. @glls Jan 25, 2019 at 3:02
  • 1
    considering the question has changed dramatically since it was originally posted, t should no longer be closed imo. I never voted to actually close it, just gave in my 2 cents when it was originally posted
    – glls
    Jan 25, 2019 at 3:06

1 Answer 1

2

I'm not aware of a specific base class for this. Happy for someone to prove me wrong though.

In the absence of a specific solution you could use an Apex trigger on Leads to detect the conversion occurring.

You want an AFTER UPDATE trigger on Lead. Check each Lead in trigger.new for IsConverted changing. The new Opportunity can be found with ConvertedOpportunityId.

Something to consider when creating the new OpportunityLineItem records is the need for the Pricebook2Id to be set on the Opportunity. Once that is set/known you can get the PriceBookEntry records that correspond to the Product2 Ids from the Leads.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .