You need to sign in to do that
Don't have an account?
rob_ocp
System.NullPointerException: Attempt to de-reference a null object
We are trying to do a trigger to calculate the amount in USD and store in a custom field in Opportunity.
But I am facing the NullPointerException
Code:
trigger opptyAmountNusd on Opportunity (after update) {
//Calculates the USD equivalent and updates in another field
if (Trigger.isUpdate) {
//for (Opportunity o_oppty : Trigger.old) {
Opportunity[] opps = new List<Opportunity>();
for (Opportunity n_oppty : Trigger.new) {
Opportunity opp_tmp = n_oppty;
if ((n_oppty.Amount != 0) ||(n_oppty.Amount != NULL) ) {
Decimal a = n_oppty.Amount;
String c = n_oppty.CurrencyIsoCode.substring(0,3);
CurrencyType ct = [Select ConversionRate from CurrencyType where IsoCode=:c limit 1][0];
Decimal cr = ct.ConversionRate;
opp_tmp.Amount_In_USD__c = cr*a;
opps.add(opp_tmp);
//n_oppty.Amount_In_USD__c = cr*a;
}
}
//}
for (Opportunity opp_tmp : opps) {
update opp_tmp;
}
}
}
Message Edited by rob_ocp on 07-10-2008 11:08 AM
Message Edited by rob_ocp on 07-10-2008 11:11 AM
Code:
trigger opptyAmountNusd on Opportunity (after update) {
//Calculates the USD equivalent and updates in another field
if (Trigger.isUpdate) {
//for (Opportunity o_oppty : Trigger.old) {
Opportunity[] opps = new List<Opportunity>();
for (Opportunity n_oppty : Trigger.new) {
Opportunity opp_tmp = n_oppty;
if ((n_oppty.Amount != 0) ||(n_oppty.Amount != NULL) ) {
Decimal a = n_oppty.Amount;
String c = n_oppty.CurrencyIsoCode.substring(0,3);
CurrencyType ct = [Select ConversionRate from CurrencyType where IsoCode=:c limit 1][0];
Decimal cr = ct.ConversionRate;
opp_tmp.Amount_In_USD__c = cr*a;
opps.add(opp_tmp);
//n_oppty.Amount_In_USD__c = cr*a;
}
}
//}
for (Opportunity opp_tmp : opps) {
update opp_tmp;
}
}
}
Message Edited by rob_ocp on 07-10-2008 11:08 AM
Message Edited by rob_ocp on 07-10-2008 11:11 AM
The culprit seems to be this line.
Let's know the result by posting the result.
All Answers
The culprit seems to be this line.
Let's know the result by posting the result.