function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mauricio OliveiraMauricio Oliveira 

Why is my query converting an amount to user's currency without using ConvertCurrency?

Hi there,

I have a trigger to keep Opportunity and Quote Line Items custom field synced. In this process I compare some of the fields of QuoteLineItem and OpportunityLineItem (to find out which ones are corresponding). So I query the items and check for some fields, including UnitPrice. When the user's profile currency is different from the related records currency, the UnitPrice is being converted in one of the objects (QuoteLineItem), but not in the other (OpportunityLineItem), so my mapping fails and my trigger does nothing because it couldn't find a matching item to sync fields. These are the queries my trigger does:
 
String qliQuery = 'select Id, QuoteId, PricebookEntryId, UnitPrice, Quantity, SortOrder, CurrencyIsoCode' + qliFields + ' from QuoteLineItem where Id in (' + qliIds + ') order by QuoteId, SortOrder ASC';
List<QuoteLineItem> qlis = Database.query(qliQuery);

String oliQuery = 'select Id, OpportunityId, PricebookEntryId, UnitPrice, Quantity, SortOrder, CurrencyIsoCode' + oliFields + ' from OpportunityLineItem where OpportunityId in (' + oppIds + ') order by OpportunityId, SortOrder ASC';
List<OpportunityLineItem> olis = Database.query(oliQuery);
Where qliFields and oliFields define which custom fields will be synced, qliIds contains the new QuoteLineItems being created, and oppIds are the IDs of the Opportunities related to the entries that fired this trigger.

These queries are done in an after insert context in the QuoteLineItem object. The result of the both queries is below (I ommited some of the irrelevant fields):
 
[Debug] COMPARING: QuoteLineItem:{Id=0QLc0000002mkaVGAQ, QuoteId=0Q0c0000000acKFCAY, PricebookEntryId=01u0B00000rRLZmQAO, UnitPrice=2855.60, Quantity=1.00, CurrencyIsoCode=USD, ...}

[Debug] COMPARING: OpportunityLineItem:{Id=00kc000000AREWCAA5, OpportunityId=006c000000GFc4SAAT, PricebookEntryId=01u0B00000rRLZmQAO, UnitPrice=1298.00, Quantity=1.00, CurrencyIsoCode=USD, ...}
Note that UnitPrice is returning 2855.60 in this query (which is 1298.00 * 2.20, our default currency conversion rate). Although, both records are registered with CurrencyIsoCode as USD (as they should be). All other records (Opportunity, Quote, PricebookEntry) are registered as USD.

So, when comparing by UnitPrice, those two records never match and my trigger fails its goal. I will remove this comparison and use other criteria for matching, so my problem will be solved for now, but I would like very much to understand this behavior.

​Any help? Thanks in advance.
Rohit Goyal 5Rohit Goyal 5
Just a thought here that the record of quote line item was created before enabing multicurrency and the record for opportunity line item was created after this enablment.
Ideally this should behave as expected if the corresponding CurrencyIsoCode is already set to USD, but keeping this as an assumption also. You can check that the issue persist for all QLI (quote line item).