You need to sign in to do that
Don't have an account?
![yujohwan99 yujohwan99](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
"Attempting to dereference a null object" error with working code?
When I make a new contact to test this code, it works perfectly fine. However, when trying to mass update over 20000 or so records, I receieve an "attempt to dereference a null object" error on the for each loop. I'm not sure why this is the case. Is this because I hit a governor limit?
List<String> joinDate = new List<String>();
Schema.DescribeFieldResult fieldResult = Contact.JoinDate__c.getDescribe();
List<Schema.PicklistEntry> pEntries = fieldResult.getPicklistValues();
for (Schema.PicklistEntry pEntry : pEntries)
{
String pe = pEntry.getValue();
if (pe.startsWith('1') || pe.startsWith('200') ||
(pe.startsWith('201') && !pe.equals('2019'))){
joinDate.add(pe);
}
}
List<Contact> massupdate = new List<Contact>();
List<Contact> cons = [SELECT Id, Name, npe01_WorkEmail__c
FROM Contact
WHERE Join_Date__c IN :joinDate];
system.debug('Number of records in list above' + cons.size());
For(Contact c: cons){
if(c.npe01_WorkEmail__c.endsWithIgnoreCase('it.work.com')){
System.debug('>>>>>>>>>' + c.npe01_WorkEmail__c);
c.npe01_WorkEmail__c = null;
massupdate.add(c);
}
}
if(!massupdate.isEmpty()){
update massupdate;
}
List<String> joinDate = new List<String>();
Schema.DescribeFieldResult fieldResult = Contact.JoinDate__c.getDescribe();
List<Schema.PicklistEntry> pEntries = fieldResult.getPicklistValues();
for (Schema.PicklistEntry pEntry : pEntries)
{
String pe = pEntry.getValue();
if (pe.startsWith('1') || pe.startsWith('200') ||
(pe.startsWith('201') && !pe.equals('2019'))){
joinDate.add(pe);
}
}
List<Contact> massupdate = new List<Contact>();
List<Contact> cons = [SELECT Id, Name, npe01_WorkEmail__c
FROM Contact
WHERE Join_Date__c IN :joinDate];
system.debug('Number of records in list above' + cons.size());
For(Contact c: cons){
if(c.npe01_WorkEmail__c.endsWithIgnoreCase('it.work.com')){
System.debug('>>>>>>>>>' + c.npe01_WorkEmail__c);
c.npe01_WorkEmail__c = null;
massupdate.add(c);
}
}
if(!massupdate.isEmpty()){
update massupdate;
}
Try this