You need to sign in to do that
Don't have an account?

UnExpected System.NullPointerException: Attempt to de-reference a null object
My Test function is
@isTest(SeeAllData=true)
static void test1(){
MirrorTestUtil.setupSettings();
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()));
Test.startTest();
insert feedList;
Test.stopTest();
}
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())
userSettingsMap.put(user.Id,GlassUserApiSettings__c.getValues(user.Id));
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 ??