I have this batchclass with which I want to update some checkboxes on account with the values of related assets checkbox values. When running the class I get an System.NullPointerException: Attempt to de-reference a null object error.
I did some research and this could be because of a null value. I made a check on all of my fields but still get this error at the following line:
asst.account.Actief_onderhoud_Design_Solutions__c = asst.design_Solutions_Product__c;
Class
global class BatchUpdateAccountByAsset implements
Database.Batchable<sObject>, Database.Stateful {
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator (
[SELECT account.Name, design_Solutions_Product__c, layertec_Product__c, simuleon_Product__c, account.Actief_onderhoud_Design_Solutions__c,
account.Actief_onderhoud_Layertec__c, account.Actief_onderhoud_Simuleon__c
FROM Asset
WHERE (design_Solutions_Product__c = true AND account.Actief_onderhoud_Design_Solutions__c = false)
OR (layertec_Product__c = true AND account.Actief_onderhoud_Layertec__c = false)
OR (simuleon_Product__c = true AND account.Actief_onderhoud_Simuleon__c = false)
]);
}
global void execute(Database.BatchableContext bc, List<Asset> scope){
List<Account> acc = new List<Account>();
if(scope.size()!=Null){
for (Asset asst : Scope) {
if(asst.design_Solutions_Product__c !=null && asst.account.Actief_onderhoud_Design_Solutions__c !=null) {
asst.account.Actief_onderhoud_Design_Solutions__c = asst.design_Solutions_Product__c;
}
if(asst.layertec_Product__c !=null && asst.account.Actief_onderhoud_Layertec__c !=null) {
asst.account.Actief_onderhoud_Layertec__c = asst.layertec_Product__c;
}
if(asst.layertec_Product__c !=null && asst.account.Actief_onderhoud_Simuleon__c !=null) {
asst.account.Actief_onderhoud_Simuleon__c = asst.simuleon_Product__c;
}
acc.add(asst.account);
}
update acc;
}
}