I'm attempting to retrieve the id of a user who created a particular KnowledgeArticleVersion and getting an "attempt to de-reference a null object" error on the line where I add creator to modifiers. Using system debug to print out kavs[0].CreatedById, though, I get

15:58:27:020 USER_DEBUG [18]|DEBUG|005i0000000jqkeAAA

which is the ID I want and implies that what I'm attempting to add to this list is not null (In this case kavs was of length 1). I even threw in a check for nullity which didn't seem to make a difference.

List<KnowledgeArticleVersion> kavs = [SELECT CreatedById FROM KnowledgeArticleVersion WHERE (KnowledgeArticleId = :kas.Id AND PublishStatus = 'online' AND Language = 'en_US')];

List<String> modifiers;
for (Integer i = 0; i < kavs.size(); i++){
        if (kavs[i].CreatedById != null){
            creator = kavs[i].CreatedById;
String modifiedBy = String.join(modifiers, ' ,');

What am I missing? I've tried a ton of different changes with no success.


You have declared List<String> modifiers;

But before instanciating as modifiers= new List<String>(); you are trying to add modifiers.add(creator);

So, modifiers is null and you are getting

Attempt to de-reference a null object

Better, declare List<String> modifiers = new List<String>(); to solve the issue.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.