I'm trying to create a queueable apex class which will update the unit prices of all Products (on all Pricebooks) based on newly updated exchange rates.
I'm able to successfully query on DatedConversionRate and get the correct rates, but when I try to pull a list of the PricebookEntries, the query does not return any data.
Below is the class which implements the Queueable interface as well as the corresponding test method.. I've performed a query on PricebookEntry using the Data Loader and successfully pulled the correct data that way, but I cannot achieve the same here.
Thanks in advance for any help
public class FXrateListPriceUpdate implements Queueable {
public void execute(QueueableContext context){
list<PricebookEntry> usdListPrices = new list<PricebookEntry>();
list<PricebookEntry> listPriceUpdates = new list<PricebookEntry>();
list<DatedConversionRate> exchangeRates = new list<DatedConversionRate>();
// load latest conversion rates based on current date
date currentDate = date.today();
exchangeRates = [SELECT Id,ConversionRate,IsoCode,NextStartDate,StartDate
FROM DatedConversionRate
WHERE IsoCode!='USD' AND NextStartDate>:currentDate AND StartDate<:currentDate];
for (DatedConversionRate conv:exchangeRates){
system.debug(conv.IsoCode + ' ' + conv.ConversionRate + ' ' + conv.StartDate + ' ' + conv.NextStartDate);
}
// load usd prices to convert based on new exchange rates
usdListPrices = [SELECT Id,CurrencyIsoCode,IsActive,Pricebook2Id,Product2Id,UnitPrice,UseStandardPrice,Product_Name__c
FROM PricebookEntry
WHERE CurrencyIsoCode=:'USD'];
for (PricebookEntry usList:usdListPrices){
system.debug(usList.Product_Name__c + ' ' + usList.CurrencyIsoCode + ' ' + usList.UnitPrice);
}
}
}
_
@isTest
public class TESTFXrateListPriceUpdate {
static testmethod void run() {
Test.startTest();
System.enqueueJob(new FXrateListPriceUpdate());
Test.stopTest();
}
}