+ Start a Discussion
Alice JuAlice Ju 

Selecting records where a datetime value meets criteria

Hi there,

 

I have a querry in my apex trigger that looks like this:

 

      List<DatedConversionRate> ExchRateCache = [SELECT ISOCode, ConversionRate,  StartDate, NextStartDate FROM DatedConversionRate where ISOCode in :CurrCodes ];

 

This works fine, but it pulls the currency exchange rate of all time, and I only want the exchange rate on the 1st day of the month. I then changed it as below.

 

      List<DatedConversionRate> ExchRateCache = [SELECT ISOCode, ConversionRate,  StartDate, NextStartDate FROM DatedConversionRate where ISOCode in :CurrCodes AND ExchRateCache.StartDate.Day()='1'];

 

But I got an error saying "unexpected token: ')' at line 70 column 192"

 

Can some one be so kind and give me some instruction? Very much appreciate!

Alice

Best Answer chosen by Admin (Salesforce Developers) 
Anil SavaliyaAnil Savaliya

Try This 

 

 List<DatedConversionRate> ExchRateCache = [SELECT ISOCode, ConversionRate,  StartDate, NextStartDate FROM DatedConversionRate where DAY_IN_MONTH(StartDate) = 1  and  ISOCode in :CurrCodes ];

All Answers

Anil SavaliyaAnil Savaliya

Try this  

 

 List<DatedConversionRate> ExchRateCache = [SELECT ISOCode, ConversionRate,  StartDate, NextStartDate FROM DatedConversionRate where  StartDate.Day()='1'  and  ISOCode in :CurrCodes ];

Alice JuAlice Ju

Hi Andy,

Thanks for the response!  It's still showing "Error: Compile Error: unexpected token: ')' at line 70 column 148" .

Anil SavaliyaAnil Savaliya

Try This 

 

 List<DatedConversionRate> ExchRateCache = [SELECT ISOCode, ConversionRate,  StartDate, NextStartDate FROM DatedConversionRate where DAY_IN_MONTH(StartDate) = 1  and  ISOCode in :CurrCodes ];

This was selected as the best answer
Alice JuAlice Ju
It works!!!! Thanks so much Andy!!
Anil SavaliyaAnil Savaliya

Please add in kudos if work fine.