0

This visualforce page renders a csv but all the data is on one row. Where did I go wrong, how do I get a new row after every apex:repeat?

Note: The code below is on one line to prevent empty header rows when rendering.

<apex:page standardController="Custom_Object__c" cache="true" contentType="text/csv#filename.csv" language="en-US"> Col A","Col B","Col C","Col D","Col E",<apex:repeat value="{!Custom_Object__c.Custom_Object_Members__r}" var="co"> {!co.Custom_Object__c.Name},{!co.Contact__r.FirstName},{!co.Contact__r.LastName},{!co.Contact__r.Email},{!co.Contact__r.MobilePhone}, </apex:repeat> 

This code all goes on line:

<apex:page standardController="Custom_Object__c" cache="true" contentType="text/csv#filename.csv" language="en-US"> Col A","Col B","Col C","Col D","Col E",
<apex:repeat value="{!Custom_Object__c.Custom_Object_Members__r}" var="co"> {!co.Custom_Object__c.Name},{!co.Contact__r.FirstName},{!co.Contact__r.LastName},{!co.Contact__r.Email},{!co.Contact__r.MobilePhone}, 
</apex:repeat></apex:page>

This code puts line break where needed (it seems a new line with anything in it adds a new row, "_" in this example.)

<apex:page standardController="Custom_Object__c" cache="true" contentType="text/csv#filename.csv" language="en-US"> Col A","Col B","Col C","Col D","Col E",
_
<apex:repeat value="{!Custom_Object__c.Custom_Object_Members__r}" var="co"> {!co.Custom_Object__c.Name},{!co.Contact__r.FirstName},{!co.Contact__r.LastName},{!co.Contact__r.Email},{!co.Contact__r.MobilePhone}, 
_
</apex:repeat></apex:page>

This example also gives line breaks.

<apex:page standardController="Custom_Object__c" cache="true" contentType="text/csv#filename.csv" language="en-US"> Col A","Col B","Col C","Col D","Col E",
_<apex:repeat value="{!Custom_Object__c.Custom_Object_Members__r}" var="co"> {!co.Custom_Object__c.Name},{!co.Contact__r.FirstName},{!co.Contact__r.LastName},{!co.Contact__r.Email},{!co.Contact__r.MobilePhone}, 
_</apex:repeat></apex:page>

For whatever reason, I need to have text before a return, the visualforce tags themselves do not trigger a new line....what the waffle....

2

You need to add a few newlines:

<apex:page standardController="Custom_Object__c" cache="true" contentType="text/csv#filename.csv" language="en-US"> Col A","Col B","Col C","Col D","Col E",
<apex:repeat value="{!Custom_Object__c.Custom_Object_Members__r}" var="co"> {!co.Custom_Object__c.Name},{!co.Contact__r.FirstName},{!co.Contact__r.LastName},{!co.Contact__r.Email},{!co.Contact__r.MobilePhone}, 
</apex:repeat></apex:page>

apex:repeat tends to be pretty literal when it comes to things like that. Make sure you don't include any space between </apex:repeat> and </apex:page> if you don't want an extra blank newline at the end.

| improve this answer | |
  • Thank you for your help, still no luck, keeps it on one line. Any thoughts? No matter how many lines I break the vf code on it still comes out as one line. – Steel Reserve 211 Sep 11 '17 at 19:37
  • If I add new lines before the Col A, Col B, etc. it does honor those, but not after. Seems Strange – Steel Reserve 211 Sep 11 '17 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.