function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

UnExpected System.NullPointerException: Attempt to de-reference a null object

My Test function is 


static void test1(){
User u = [Select Authorize__c From User Where Id = :UserInfo.getUserId()];
u.Authorize__c = true;
update u;
List<FeedItem> feedList= new List<FeedItem>();
for (Integer i = 0; i<10;i++)
feedList.add( new FeedItem(Body='Hello World'+i,ParentId = UserInfo.getUserId()));
insert feedList;


as u can see i updated User Authorize__c = true;

from this a trigger get called after that because its bulk that why i am doing my operation as Batch apex .code for that is here 

public class PublishGlassTimeLine implements Database.Batchable<sObject>{
SObjectIterable iterable;
Map<Id,User> userMap;
Map<Id,GlassUserApiSettings__c> userSettingsMap;
Map <String,String> contentmap;

public PublishGlassTimeLine(List<sObject>objectList,Map<String,String> contentmap){
iterable = new sObjectIterable(objectList);
this.userMap = new Map<Id,User>([Select Id,Name From User WHERE Authorize__c = true]);
userSettingsMap = new Map<Id,GlassUserApiSettings__c>();
System.debug('user map is '+userMap);
System.debug('user map values are '+userMap.Values());
for(User user: userMap.Values())
this.contentmap = contentmap;

public Iterable<sObject> start(Database.BatchableContext BC){
return iterable;

public void execute(Database.BatchableContext BC, List<sObject> scope){
GMirrorUtil.createTimeLine(scope, contentMap);

public void finish(Database.BatchableContext BC){
System.debug('Job Has been Finished');

its giving me error

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PostFeedsToTimeLine: execution of AfterInsert

caused by: System.NullPointerException: Attempt to de-reference a null object

Class.BatchPublishTimeLine.<init>: line 11, column 1
Trigger.PostFeedsToTimeLine: line 4, column 1: []

he is referring null object to userMap.

but i think it should not be null.

can any one please tell why i am facing this NullPointer exception ??