+ Start a Discussion

an exception is thrown when i'm trying to add id's to a set

Hi all,
I want retreive all the lead records other than previously owned by the user.So i'm querying the Lead history object to fetch all the leads which are previously owned by him .This query is retriving the records but when i'm adding leadId's to a set an exception is thrown saying Attempt to de-reference a null object' at that line.
This is the part of the code i'm using
String CurrentUserId = UserInfo.getUserId();
      Set<Id> t1= new Set<Id> ();
  leadHistory[] lh1=[select leadId from leadHistory where field='Owner' and createdById=:CurrentUserId ];
      for(leadHistory lh2:lh1)
       for(List<Lead> myVar1 :[select id, name, Status from Lead where Status='Open' and Postcode__c!= null and id not in :t1 ])
     myVar =myVar1 ;
.Any pointers will be of great help.Thanks in advance.

 I didn't found any bug, but mean while if u want, you can use the following code.

                for(Integer c=0;c<lh1.size();c++)
                t1.add( lh1[c].leadId);