You need to sign in to do that
Don't have an account?
Alfredo Puente Vasconcelos
Problem With Attachment null on Email Message Trigger
Hello everyone, I'm having some issues while I try to get the attachments on an Email Message trigger. I want to block all the emails that have Excel Files attached but when I try to access the Attachments, Apex says the the list is Empty. Can someone help me? :(
Thanks for your time
trigger BlockExcel on EmailMessage (before insert) { List<EmailMessage> compatibleEmails = new List<EmailMessage>(); for(EmailMessage activeMail : Trigger.new){ if(activeMail.HasAttachment == true && activeMail.Subject.contains('Entrega de propuesta')){ compatibleEmails.add(activeMail); }else{ System.debug('Dont Enter'); } } for(EmailMessage email : compatibleEmails){ /*********************ERROR Attachment Size = 0***********/ System.debug('The size of my attachment list is: ' + email.Attachments.size()); for(Integer i = 0; i < email.Attachments.size(); i++){ if(email.Attachments[i].ContentType == '.xlsx' || email.Attachments[i].ContentType == 'xlsx'){ email.addError('Excel Files are not allow'); break; } } } }
Thanks for your time
pankul gupta
The code seems to be fine, just trythe below, . should be prefixed before xlsx and moreover can you please explain how are you trying to test the same:
Alfredo Puente Vasconcelos
Yes I should fix the If clause but my real problem is that my Attachments list is empty. I have a Debug in my code to see the size of the Attachment list when my trigger is activated. So when I send emails to test the trigger I take a look to my logs in my developer console and I noticed that always the Attachment list is empty.