简体   繁体   English

尝试取消引用空对象错误

[英]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.

相关问题 错误:System.NullPointerException:尝试取消引用空对象 - Error: System.NullPointerException: Attempt to de-reference a null object Salesforce:尝试取消引用空对象 - Salesforce: Attempt to de-reference a null object 获取System.NullPointerException:尝试取消引用Null对象错误 - Getting a System.NullPointerException: Attempt To De-reference A Null Object error Visualforce过滤的相关列表错误:无法显示内容:尝试取消引用空对象 - Visualforce filtered related list error: Content cannot be displayed: Attempt to de-reference a null object 尝试取消引用空对象 Salesforce Visual Force 页面 - Attempt to de-reference a null object Salesforce Visual Force Page System.NullPointerException:尝试取消引用空对象 - System.NullPointerException: Attempt to de-reference a null object php:System.NullPointerException:尝试取消引用空对象 - php : System.NullPointerException: Attempt to de-reference a null object System.NullPointerException:尝试取消引用空对象 - System.NullPointerException: Attempt to de-reference a null object JMeter&Salesforce:遇到错误,因为“加载Visualforce页面时发生错误。 尝试取消引用空对象&#39; - JMeter & Salesforce : Facing an error as 'Error occurred while loading a Visualforce page. Attempt to de-reference a null object' System.NullPointerException:尝试取消引用空对象,但值不为null - System.NullPointerException: Attempt to de-reference a null object but value is not null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM