[英]Attempt to de reference a null object error
On line acct.AmountX__c += amtX
this and acct.AmountY__c += amtY
this it is giving me an error.在线
acct.AmountX__c += amtX
this 和acct.AmountY__c += amtY
this 给我一个错误。 The trigger is on after insert and after update.触发器在插入后和更新后开启。 When i am inserting any record in contact then it is giving me an error i don't know why.
当我在联系人中插入任何记录时,它给了我一个错误,我不知道为什么。 Why should '
acct
' be initialized if i am not wrong this error comes when you have not initialized something.如果我没有错,为什么要初始化 '
acct
' 这个错误是因为你没有初始化某些东西。
public class ContactAccountRollUpAmount {
public static void onAfterInsertOrUpdate(List<Contact> cont){
contAccRollUpAmount(cont);
}
public static void contAccRollUpAmount(List<Contact> contactList){
List<Contact> cont = new List<Contact>([Select AccountId, Amount_Type__c, Amount__c
from Contact
where id in: contactList]);
List<Account> accList = new List<Account>([Select id, AmountX__c, AmountY__c
from Account Limit 50000]);
List<Account> accListToUpdate = new List<Account>();
for(Account acct: accList){
Double amtX = 0;
Double amtY = 0;
system.debug('#########'+acct);
for(Contact con: cont){
if(con.AccountId == acct.Id){
if(con.Amount__c != NULL){
if(con.Amount_Type__c == 'AmountX'){
amtX = amtX + con.Amount__c;
} else if(con.Amount_Type__c == 'AmountY'){
amtY = amtY + con.Amount__c;
}
}
}
}
if(amtX != NULL){
acct.AmountX__c += amtX;
}
if(amtY != NULL){
acct.AmountY__c += amtY;
}
accListToUpdate.add(acct);
}
if(accListToUpdate.size()>0){
update accListToUpdate;
}
}
}
The problem is not that the ' acct
' is not initialized, its the field 'AmountX__c' and 'AmountY__c'.问题不在于“
acct
”未初始化,而是字段“AmountX__c”和“AmountY__c”。
As I can see you have queried max of 50000 records, out of these records some of them have 'Null' values for the above two fields.正如我所看到的,您最多查询了 50000 条记录,其中一些记录的上述两个字段的值为“Null”。
I suggest please check whether the above two fields have 'Null' values for some records or not.我建议请检查上述两个字段是否有某些记录的“空”值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.