Can someone explain the error? I have a trigger that passes a set of Event IDs to an @future clas. Below is the class:

    public class eventChatterFuture{

    public static void FutureEventChatterMethod(set <id> empId){

    Set < id> empIds = empId;
    Set<ID> ownerIds = new Set<ID>();
    List<FeedItem> feedItems = new List<FeedItem>();

     list <event> theEs  = [select WhatId, WhoId, Subject, ownerID, Description from event  where ID IN: empids];
     system.debug ('theEs===================='+ theEs);

     for (event E : theEs){
     system.debug('ownerIDs-------------' + ownerids);

      Map<ID,User> userMap = new Map<ID,User>([SELECT ID, Name FROM User WHERE ID IN :ownerIds]); //This is our user map

     System.debug('usermap------------------------' + usermap);

      for (event t : theEs) {
        if (t.WhatId != null ) {
            FeedItem fitem = new FeedItem();
            fitem.type = 'LinkPost';
            fitem.ParentId = t.WhatId;
            fitem.LinkUrl = '/' + t.id; //This is the url to take the user to the activity
            fitem.Title = 'View';  //This is the title that displays for the LinkUrl

            //Get the user by checking the userMap we created earlier
           User assignedTo = userMap.get(t.ownerId);
           system.debug('userassignedTo-------------------' + assignedTo );

            fitem.Body = ((Trigger.isInsert) ? '' : '') + ' Meeting' + ((t.ActivityDate != null) ? t.ActivityDate.format() :'')
                      //  + '\nWho: '  + t.Who
                        + '\nSubject: ' + t.Subject
                        + '\nNotes: ' + t.Description


      if (feedItems.size() > 0) {
        Database.insert(feedItems,false); //notice the false value. This will allow some to fail if Chatter isn't available on that object

The error I get is:

14:21:23.095 (95746000)|USER_DEBUG|[32]|DEBUG|userassignedTo-------------------User:{Name=John Alston, Id=005U0000000OnR8IAK}
14:21:23.095 (95752000)|SYSTEM_METHOD_EXIT|[32]|System.debug(ANY)
14:21:23.095 (95897000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Class.eventChatterFuture.FutureEventChatterMethod: **line 32**, column 1
14:21:23.095 (95916000)|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object

Please note that line 32 is the system.debug that just ran successfully above! If I comment this line out, the null pointer just migrates to other lines.

Any help appreciated, thanks!

1 Answer 1


The error is actually the next line:

if(Trigger.isInsert ...)

You're in a future method, which means you can't be in a trigger context. The trigger's context has already evaporated when this code is triggered, and a future-invoked trigger can't invoke a future method, so it is impossible for the Trigger object to ever be valid within the body of a future method.

If you want to know if the trigger was an insert, you must pass this as a parameter to the future method. I think it's odd that it states that line 32 is the problem, but the problem is definitely the statement following.

  • Thanks! You can probably guess that I copied the bulk of this from a trigger that works on Events inserted from the browser UI without this issue.
    – jaw999
    Commented Jan 15, 2014 at 20:38
  • For anyone else reading, I changed the line I just deleted out the Trigger ref part in that line and it seems to be working. Thanks again.
    – jaw999
    Commented Jan 15, 2014 at 20:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .