I am unable to fix the error System.NullPointerException: Attempt to de-reference a null object on my trigger.
Could someone help? Thanks
trigger Knowledge_kavKnownErrorSubscription on Knowledge__kav (after insert, after update) { List<Known_Error_Subscription__c> kesList = new List<Known_Error_Subscription__c>(); for(Knowledge__kav kav : [SELECT Id, Known_Error_Status__c, VersionNumber, Title, KnowledgeArticleId, (SELECT Knowledge__c FROM Known_Errors_Subscriptions__r) FROM Knowledge__kav WHERE Id IN :Trigger.New]) { if(kav.KnowledgeArticleId != null &&(Trigger.oldMap.get(kav.Id).LastPublishedDate != Trigger.newMap.get(kav.Id).LastPublishedDate)) { Known_Error_Subscription__c kes = kav.Known_Errors_Subscriptions__r; kes.Knowledge__c = kav.KnowledgeArticleId; kesList.add(kes); } } if(kesList.size() > 0) { update kesList; } }
Known_Errors_Subscriptions__r, until which it will be null, and you will get null pointer exception.