+ Start a Discussion
ssousanssousan 

How to create a text file and send the text file via email?

In APEX,

I want to write a few variables to a text file and send the text file via email,

 

I don't want to save the text file as a document,

I have no use for it, and I don't want to accumulate text files on Salesforce,

 

Does anyone know how to do this?

Or can lead me to a thread that does something similar,

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
You can use Blob.valueOf(String) to encode the text into an attachment directly, which can be attached to the email. Take a look at the SingleEmailAttachment methods in the documentation.