You need to sign in to do that
Don't have an account?
Hermann Ouré
knowledge__kav System.NullPointerException: Attempt to de-reference a null object
Hello,
I am unable to fix the error
System.NullPointerException: Attempt to de-reference a null object on my trigger.
Could someone help?
Thanks
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 KnowledgeArticleId, Known_Error_Status__c, VersionNumber, (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; } }
You can use the below updated code:
Let me know if there is any issue.
Thanks,
Abhishek Bansal.
All Answers
Greetings!
You would need to add the logic in the if block whenever you are trying to access or use the list.
Reference:https://help.salesforce.com/HTViewSolution?id=000063739
Please mark it as best answer if it helps you to fix the issue.
Thank you!
Regards,
Shirisha Pathuri
There is no old map in case of after insert so you need to add additional checks in order to access the trigger.oldMap only in case if the record is updated. Let me know if you need any other help or informaiton on this.
Thanks,
Abhishek Bansal.
Hi Abhishek,
I would appreciate if you could give me extra informations on how to access trigger.oldMap
Thanks,
Hermann
You can use the below updated code:
Let me know if there is any issue.
Thanks,
Abhishek Bansal.