0

I have a simply spam classification logic in trigger which runs when a community user posts a post (FeedItem) in experience cloud sites (community sites).

trigger FeedItem_Operation_Trigger on FeedItem (before insert,
                                                before update,
                                                before delete,
                                                after insert,
                                                after update,
                                                after delete) {
    if(Trigger.IsBefore && Trigger.IsUpdate){
        Map<Id,sObject> oldMap = Trigger.OldMap;
        List<sObject> newRecords = Trigger.NewMap.values();

        List<sObject> changedRecords = new List<sobject>();
        for(sObject so : newRecords){
            System.debug('isUpdateable  '+Schema.sObjectType.FeedItem.fields.Status.isUpdateable ());
             System.debug('isCreateable '+Schema.sObjectType.FeedItem.fields.Status.isCreateable());

            Boolean isSpam =  CSFP.classifyAsSpam(so); // returns true or false
            if(isSpam){
                so.put('Status', 'PendingReview');
            } else 
                if(so.get('Status') == 'PendingReview'){
                    so.put('Status', 'Published');
                
            }
        
    }
                                            
   
}

whenever someone updates a post(FeedItem), it checks its content and classifies it as spam or not. If it is spam it changes status to PendingReview, else Published.

However I get the following error,

You need permission to change the status of this feed item. Ask your admin.

Now I have following doubts.

--> Trigger runs in System Context, how is it that FLS are needed.

--> I logged isCreateable and isUpdateAble check on status of FeedItem both were true.

Note : I have same algorith that runs on insert and it correctly changes status to 'PendingReview' without error. Am I missing something?

5
  • The 'community' tag is for experience cloud sites (fka community sites).
    – Derek F
    Jun 16, 2022 at 11:13
  • @DerekF Yes when a community user posts in a community site
    – AmanSharma
    Jun 16, 2022 at 11:22
  • Maybe the community user doesn't have access to update the feeditem. Could you please verify the permissions on the community user profile?
    – Mehedi
    Jun 16, 2022 at 11:24
  • @HasanOnM but trigger runs in system context and user level permission can be ignore right? and also i tried System.debug('isUpdateable'+Schema.sObjectType.FeedItem.fields.Status.isUpdateable ()); System.debug('isCreateable'+Schema.sObjectType.FeedItem.fields.Status.isCreateable()); Both retuning true;
    – AmanSharma
    Jun 16, 2022 at 11:36
  • does community user have Can Approve Feed Post permission?
    – cropredy
    Jun 16, 2022 at 20:31

0

You must log in to answer this question.

Browse other questions tagged .