function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Satish Kumar LalamSatish Kumar Lalam 

My email to Feeditem code is failing for few Pdf files

I wrote a code to catch the email replies into case feeditem object. below is my code and its working fine for all the attachments but failing for few PDF files. could anyone please if am Missing anything here.

Trigger : 

trigger emailToPostChatter on EmailMessage (After insert) {
    
    Set<Id> EmailId = new Set<Id>();
    for (EmailMessage email : trigger.new) {
        
        if(email.FromAddress !='ssp-support-test@sureify.com'){
            List<User> u = [select Id, Name, Email from user where Email =: email.FromAddress AND isActive = true];
            FeedItem post = new FeedItem();
            post.ParentId = email.ParentId;
            
            post.Visibility = 'AllUsers';
            post.createdById = u[0].Id;
            post.Title = 'EmailMessageFeed';   
            string emailBody = email.TextBody;
            
            
            
            post.Body = '\n' + emailBody;
       
            insert post;
            
            if(email.HasAttachment){
                system.debug('EmailMessage Id inside If = '+ email.Id);
                emailToPostChatterHelper.InsertFeedAttachment(email.Id, Post.Id, u[0].Id, email.ParentId);
                
            }
            else{
                emailToPostTochatterAlerts.fireExternalEmail(email.ParentId, post.Id);
                emailToPostTochatterAlerts.fireInternalEmail(email.ParentId, post.Id);
            }

        } 
    }
}

===== > Helper class to handle attachments

public class emailToPostChatterHelper {
    @future
    Public static void InsertFeedAttachment(Id emailId, Id postId, Id userId, Id CaseId){
              List<ContentDocumentLink> contDocLinks = [select Id, LinkedEntityId, ContentDocumentId from ContentDocumentLink where LinkedEntityId =: emailId];
              List<ContentDocument> cntdList = new List<ContentDocument>();
              List<ContentVersion> cntvList = new List<ContentVersion>();
              List<FeedAttachment> FeedAtchlist = new List<FeedAttachment>();
              set<Id> FeedId = new set<Id>();
  
            if(contDocLinks.size()!=null){
            for(ContentDocumentLink contD : contDocLinks){
                ContentVersion contvrsn = [select Id from ContentVersion where ContentDocumentId =:contD.ContentDocumentId];
                
                ContentDocument cntd = new ContentDocument();
                cntd.Id = contD.ContentDocumentId;
                cntd.OwnerId = userId;
                cntdList.add(cntd);
               
                
                FeedAttachment feedAttachment = new FeedAttachment();
                feedAttachment.FeedEntityId = postId;                          //Id of FeedItem
                
                feedAttachment.RecordId = contvrsn.Id;
                system.debug('emailToPostChatterHelper feedAttachment.RecordId ='+feedAttachment.RecordId);
              
                  feedAttachment.Type = 'Content'; 
                  
                 FeedAtchlist.add(feedAttachment);
                
                }
                
              
                insert FeedAtchlist;
                update cntdList;
          
            }
         
    }

}
SwethaSwetha (Salesforce Developers) 
HI Satish,

> Could you describe in more detail how the code is failing for these PDF files? Are there any error messages or specific issues that occur? What does it show in debug logs?

> Are there any patterns related to the size or content of the PDF files that fail? For instance, are they unusually large or contain specific content that might be causing the issue?

> Have you inspected the content of the PDF files that fail to see if there's anything unique about them compared to other attachments?


> PDF files may contain special characters and encoding issues. Have you checked for character encoding or special characters in these problematic PDF files that might affect their processing?

Important Update
User-added image
We appreciate your participation in these Salesforce Discussion Forums! It’s active members like you that keep our amazing community going strong.

At this time, we want to give you a heads up that on December 4, 2023, the discussion forums will shut down and all relevant discussions will migrate to the Trailblazer Community digital platform. This move brings all conversations around Salesforce development together in one place and provides more opportunities for our broader community to connect and share. We will be removing outdated, obsolete, or spam content and migrating only relevant discussions to the Trailblazer Community digital platform.

Starting November 20, you can view discussions but not post new questions or responses. On December 2, you will no longer be able to access the discussion forums from the Salesforce Developers website.

Please take these steps before November 30, 2023, 11:59 p.m. PT to ensure your contributions follow you to the Trailblazer Community:
  1. If you’re not already a member of the Trailblazer Community, sign up for a Trailblazer account using the same login email address associated with your Developer Discussion Forums account. This is crucial.
  2. If you already have a Trailblazer account, and it’s using a different email address from the one you used for your Developer Discussion Forums account, we recommend that you log in to the Trailblazer Community and connect your forums email address to your Trailblazer account.
Once you’re in the Trailblazer Community, join the Migration Support Hub users group to help you navigate this transition.

We will keep you up to date throughout the transition, and we look forward to seeing you joining the developer discussions in the Trailblazer Community!

Sincerely,
The Forums Support Team
 
Satish Kumar LalamSatish Kumar Lalam
Hi Swetha,

Sadly, I couldnt able to observe any of the mentioned above.

1. The joblogs are not generating. I am totally helpless on this part.
2. Dont see much difference with other PDF files in terms data formating and Size is in KBs only.