Quantcast
Channel: Active questions tagged feeditem+chatter - Salesforce Stack Exchange
Viewing all articles
Browse latest Browse all 68

Only Trigger Apex when File is not uploaded via chatter feed on Case

$
0
0

I have an apex trigger that creates a Chatter post on a case when a file is uploaded to that case. The code is working perfectly fine, the issue is I want to be able to restrict this code to only run when the file is uploaded to case through any means EXCEPT when uploaded by way of Chatter post.

Is there a way to identify if a ContentVersion/ContentDocument/ContentDocumentLink was uploaded via chatter? I thought the Origin field on ContentVersion might be useful, however it seems all of the files have a value of "C" no matter what.

Here is my code:

public class ContentDocumentLinkTriggerHandler {public static void OnAfterInsert(List<ContentDocumentLink> cdlRecords){    for(ContentDocumentLink a: cdlRecords){        if(String.valueOf(a.LinkedEntityId).substring(0,3) == '500'){            ContentDocument file = [SELECT Id, LatestPublishedVersionId                                    FROM ContentDocument                                    WHERE Id =: a.ContentDocumentId];            FeedItem post = new FeedItem();            post.body = 'File Uploaded';            post.parentId = a.LinkedEntityId;            insert post;            FeedAttachment postAttachment = new FeedAttachment();            postAttachment.FeedEntityId = post.id;            postAttachment.Type = 'Content';            postAttachment.RecordId = file.LatestPublishedVersionId;            insert postAttachment;        }      }    }}

Viewing all articles
Browse latest Browse all 68

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>