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
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.