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);


public class TESTFXrateListPriceUpdate {
    static testmethod void run() {

        System.enqueueJob(new FXrateListPriceUpdate());


2 Answers 2


Because of Database Isolation, your test code can't see real price books or price book entries. Make sure you create all the data you need:

Product2 productRecord = new Product2(Name='Test',IsActive=true,CurrencyIsoCode='USD');
insert productRecord;
PricebookEntry priceEntryRecord = new PricebookEntry(IsActive=true, UnitPrice=9.99, Product2Id=productRecord.Id, Pricebook2Id=Test.getStandardPricebookId());
insert priceEntryRecord;
System.enqueueJob(new FXrateListPriceUpdate());
  • Yes, I realized I simply needed SeeAllData on my test to, well, see all data... Thanks!
    – Nick
    Commented Apr 20, 2018 at 22:18
  • No! That's not what he's saying, you have to actually create the data.. Sure you can do SeeAllData but that's not recommended
    – EricSSH
    Commented Apr 20, 2018 at 22:19

You never create PriceBook Entries in your test class


  • Got it, I guess you don't need SeeAllData to query on live DatedConversionRate - that was what confused me. Thank you!
    – Nick
    Commented Apr 20, 2018 at 22:15

You must log in to answer this question.

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