+ Start a Discussion
komathipriyakomathipriya 

Updating chatter for case creation in the customer portal

Hi,

I need to show update for the salesforce user in the chatter for every case insert and update 
in my customer portal.     for that i worte a trigger in the case object  as 

trigger ChatterUpdate on Case (after insert, after update) {

    List<FeedItem> feedItems = new List<FeedItem>();
    List<Account> lstaccount =[select id,name,IsCustomerPortal from Account];
      //Now loop though the new/updated tasks and create the feed posts
    for (Case cas : Trigger.new) {
         for(Account acc: lstaccount){    
      
        if(acc.IsCustomerPortal == true )  {                               
            FeedItem fitem = new FeedItem();          
            fitem.ParentId = acc.id;
            fitem.LinkUrl = '/' + cas.id; //This is the url to take the user to the activity
            fitem.Title = 'View';  //This is the title that displays for the LinkUrl           
            fitem.Body = ((Trigger.isInsert)? ' : New Case has been Created ' : ' : Case has been updated')  
                      +  '\nCase with subject  : '+ cas.subject;
          
    feedItems.add(fitem);
       }
      } 
    }

    //Save the FeedItems all at once.
    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
    }
} 

But i'm not getting any update feed in my chatter.

Any idea to solve the problem.     

bob_buzzardbob_buzzard

Have you tried adding some debug to check that you are getting as far as the creation of the feed items?

komathipriyakomathipriya

Ya i'm getting error as follows.

 

Database.Error[getFields=();getMessage=Entity is read-only:

 FeedItem;getStatusCode=CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

 

Even this error is for the customer portal user only. if i create case from my account in salesforce org means i'm not getting error.

bob_buzzardbob_buzzard

That sounds very much like the customer portal doesn't have access to chatter.  I vaguely recall reading something about this - have you checked the licensing?

 

If that is the case, one workaround may be some scheduled apex that locates all of the cases raised by portal users and creates feed items from those.  It won't be in real time though - the granularity isn't much better than 1 hour I believe.