I'm looking for a way to access the QuoteLineItem from a OpportunityLineItem trigger when I sync a Quote with the Opportunity. How can I access the related QuoteLineItem? I looked at the "Custom Quote Sync" package on AppExchange, and the package doesn't seem to be working in my Salesforce.com instance.


3 Answers 3


Following my research, there's no "built-in" way to achieve this. However, I found an interesting thing helping me doing it: the IDs of your QuoteLineItem are in the exact same order as your OpportunityLineItem. Knowing this, you can match/sync data grammatically with two simple SOQL request (to obtain the two lists, ordered by ID) and match them one by one (first OpportunityLineItem with first QuoteLineItem...). You can implement this with triggers or with a button (depending on your business process).

I also suggest to add a lookup field linking the QuoteLineItem object to your OpportunityLineItem object. When you sync them, populate the field with the related quote item ID. Following this, you will be able to access QuoteLineItem information using formulas from your product.

  • 1
    I'll have to test this. I think at one point I thought they were non-deterministic because of some odd behavior I saw, but if this is true, it certainly is good news. Thanks for this tidbit.
    – sfdcfox
    Jul 20, 2013 at 13:10

Seems simple unless I am missing something here. If you are looking to access the Quote in a OpportunityLineItem trigger,

Get the Opportunity Id from your OpportunityLineItem.

Id oppId = olm.OpportunityId;


SELECT Id FROM Quote WHERE OpportunityId = :oppId 

EDIT after question was modified: The above logic helps you do a match up at the Opp-Quote level. Syncing the actual QuoteLineItem with the OppLineItem will be more trickier.

You can get the list of line items from the respective quote and Opp. You will need to match them up based on the PricebookEntryIdperhaps?

  • Nope, I want to associate each OpportunityLineItem with the related QuoteLineItem.
    – jpmonette
    Mar 6, 2013 at 20:54
  • It seems that is not what your question is asking though. Would you be able to edit your question with what you want to do? If you just want to just get the quote ID you can do what Richard suggested or go one step further and put a WHERE isSyncing = TRUE at the end
    – jnoel10
    Mar 6, 2013 at 21:03
  • Sorry, it was a typo =/!
    – jpmonette
    Mar 6, 2013 at 21:07
  • Np jp. And to jnoel10's point you will need to check for the quote which was synced. I think you can also do something like when you have the opp object. 'Opportunity.SyncedQuote.Id'
    – Richard N
    Mar 6, 2013 at 21:19
  • @RichardN If you have multiple product with the same PriceBookEntryId, you cannot identify them.
    – jpmonette
    Mar 20, 2013 at 16:13

You cannot identify the OpportunityLineItem associated with a QuoteLineItem. This is a pain point in our project, too. Our "solution" was to match the line items based on multiple criteria, such as PricebookEntryId, Quantity, UnitPrice, and Discount. In the event that two are identical, we simple update both of them and hope for the best. We're hoping that salesforce.com addresses this in the future.

  • You can check the answer I added, I found a solution in the past and forgot about this question. I think it's a dirty workaround, but it does match perfectly the two objects :)! Thanks for your answer!
    – jpmonette
    Jul 19, 2013 at 22:19

You must log in to answer this question.

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