You need to sign in to do that
Don't have an account?
sumanth v 18
Null pointer exception on converstion rates
I am trying to fetch converstion rate in Billingmonth [Custom Object] batch job
[Converstion rate- Currency Exchange]
Map<String, DatedConversionRate> conversionRates = new Map<String, DatedConversionRate>();
set < string > ISOCodes = new set < string > ();
String dtStr;
Date dt;
for (sObject Oppline: scope) {
opportunitylineitem op = (opportunitylineitem) Oppline;
Lineid.add(op.LineId__c);
ISOCodes.add(op.CurrencyIsoCode);
}
dtStr =system.today().year()+ '-'+ system.today().month()+ '-'+'01';
dt = Date.valueof(dtStr);
if (ISOCodes.size() > 0) {
for (DatedConversionRate ex: [Select id, StartDate, ConversionRate, IsoCode from DatedConversionRate where StartDate >= : dt and IsoCode IN: ISOCodes]) {
system.debug('@@@DateKey-->' + string.ValueOf(ex.StartDate.month()) + string.ValueOf(ex.StartDate.year()));
conversionRates.put(string.ValueOf(ex.StartDate.month()) + string.ValueOf(ex.StartDate.year()), ex);
system.debug('@@@@@@@@'+conversionRates+bm.Placement_Line_ID__c);
}
}
String str;
str = String.ValueOf(system.today().month()) + String.ValueOf(system.today().year());
system.debug('@@@@@@@@123'+conversionRates);
bm.Conversion_Rate__c = conversionRates.get(str).ConversionRate; [I am getting null pointer exception in this line.]
[Converstion rate- Currency Exchange]
Map<String, DatedConversionRate> conversionRates = new Map<String, DatedConversionRate>();
set < string > ISOCodes = new set < string > ();
String dtStr;
Date dt;
for (sObject Oppline: scope) {
opportunitylineitem op = (opportunitylineitem) Oppline;
Lineid.add(op.LineId__c);
ISOCodes.add(op.CurrencyIsoCode);
}
dtStr =system.today().year()+ '-'+ system.today().month()+ '-'+'01';
dt = Date.valueof(dtStr);
if (ISOCodes.size() > 0) {
for (DatedConversionRate ex: [Select id, StartDate, ConversionRate, IsoCode from DatedConversionRate where StartDate >= : dt and IsoCode IN: ISOCodes]) {
system.debug('@@@DateKey-->' + string.ValueOf(ex.StartDate.month()) + string.ValueOf(ex.StartDate.year()));
conversionRates.put(string.ValueOf(ex.StartDate.month()) + string.ValueOf(ex.StartDate.year()), ex);
system.debug('@@@@@@@@'+conversionRates+bm.Placement_Line_ID__c);
}
}
String str;
str = String.ValueOf(system.today().month()) + String.ValueOf(system.today().year());
system.debug('@@@@@@@@123'+conversionRates);
bm.Conversion_Rate__c = conversionRates.get(str).ConversionRate; [I am getting null pointer exception in this line.]
Here you are assigning null value =check this one in debug log values( conversionRates.get(str).ConversionRate);
Thanks
Varaprasad