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
Jayesh Deo 2Jayesh Deo 2 

Method does not exist or incorrect signature: void add(Messaging.EmailAttachment) from the type List<Messaging.EmailFileAttachment>


User-added image

I am trying to add PDF attach to email but mentioned error displayed for Line 81. Please help
Best Answer chosen by Jayesh Deo 2
SwethaSwetha (Salesforce Developers) 
HI Jayesh,
The complete code is not included in the question. So based on my understanding, looks like you are trying to use the add() method on a List<Messaging.EmailFileAttachment> object, which does not exist. To add a PDF attachment to an email, you need to use the add() method on an instance of Messaging.EmailFileAttachment.

This related example can help you:
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

// Set the recipient, subject, and body of the email
email.setToAddresses(new List<String>{ 'example@salesforce.com' });
email.setSubject('Sample Email with Attachment');
email.setPlainTextBody('Please see the attached PDF.');

// Create an instance of EmailFileAttachment
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setFileName('Attachment.pdf');
attachment.setBody(blob.valueOf('PDF content'));

// Add the attachment to the email
email.setFileAttachments(new List<Messaging.EmailFileAttachment>{ attachment });

// Send the email
Messaging.SendEmailResult[] results = Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{ email });

If this information helps, please mark the answer as best. Thank you

All Answers

SwethaSwetha (Salesforce Developers) 
HI Jayesh,
The complete code is not included in the question. So based on my understanding, looks like you are trying to use the add() method on a List<Messaging.EmailFileAttachment> object, which does not exist. To add a PDF attachment to an email, you need to use the add() method on an instance of Messaging.EmailFileAttachment.

This related example can help you:
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

// Set the recipient, subject, and body of the email
email.setToAddresses(new List<String>{ 'example@salesforce.com' });
email.setSubject('Sample Email with Attachment');
email.setPlainTextBody('Please see the attached PDF.');

// Create an instance of EmailFileAttachment
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setFileName('Attachment.pdf');
attachment.setBody(blob.valueOf('PDF content'));

// Add the attachment to the email
email.setFileAttachments(new List<Messaging.EmailFileAttachment>{ attachment });

// Send the email
Messaging.SendEmailResult[] results = Messaging.sendEmail(new List<Messaging.SingleEmailMessage>{ email });

If this information helps, please mark the answer as best. Thank you
This was selected as the best answer
Jayesh Deo 2Jayesh Deo 2
Hi Swetha,

Thanks for your Answer! It helped.
I updated below highlighted declared object and after that code ran without error.
User-added image
Jayesh Deo 2Jayesh Deo 2
Marked as best Answer. Lets connect on Linkedin/ trailhead. Please share profile if possible