I have a situation where I need to export the data from salesforce object and generate the txt or csv file for our client to read and process.I can not use data loader beacuse file should be of a fixed size.Can someone please guide me how to process with the change.

The 3rd party reads this Text document as a set of strings. i.e. for ex: 1st 10 characters would be First name and 2nd 10 characters is second name and goes on..... if in this case if I want to send a simple text 'ASHOK KUMAR' then text attachment should be 'ASHOK(5 Spaces)KUMAR(5SPACES)' .this 5 spaces would be derived dynamically as in case of 'RAVI HEER' it can be 6 spaces after each string and this goes on. I am not able to achieve this particular bit of adding these extra bit of spaces between two strings or end of a string.

enter image description here

1 Answer 1


Fixed width text files are not CSV (CSV means "comma-separated values").

In Apex Code, you'd write:

String row = firstName.rightPad(10).left(10) +
  lastName.rightPad(10).left(10) +
  // and so on...

Make sure the input variables are first set to an empty string if they are null.

In Visualforce, you can use RPAD:


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .