You need to sign in to do that
Don't have an account?

Create a text file using APEX
Any idea how to create a text file in APEX using values in a list of objects? I have a list of Accounts, the text file must be formatted in a specific format, e.g.. Account Number (1 – 16) right justified, Account Name (17 - 47) left justified, Account Site (47 - 50) right justified.
Thanks for your suggestion, we have decided to export the records from Salesforce and build the file using an external application.
All Answers
Something like this:
This code assumes that there are no null pointers in your variables. Adjust accordingly.
Basically, I make heavy use of substring to create padding and trimming effects. Note that "strings" must be at least as big as your biggest possible padding or you will run into exceptions.
Thanks for your suggestion, we have decided to export the records from Salesforce and build the file using an external application.