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
AlexandreAlexandre 

How to loop 6 times?

Hi, I have this html in a visual force page. I am trying to repeat this code 6 times. Is there a for-loop function in apex that will allow me to do this.


such as


for (int x=0; x6; x++){

<table style="width:700px"><tr>
<td valign="middle" align="center">
<br/><br/><h1>Commercial Invoice</h1>
</td>
<td>
<img id="theImage" src="https://na1.salesforce.com/servlet/servlet.FileDownload?file=01530000000mvyc" />

</td>
</tr>
</table>

 
}

Message Edited by Alexandre on 05-25-2009 07:18 AM
hokusaihokusai
why can't you copy and paste six times?  This is a visualforce page and not apex.  If you want to use the <apex:repeat tag then you will need a controller with list property with 6 elements
AlexandreAlexandre
It cant copy paste because its 17 pages long and it changes often. I only showed the first few line. Seriously... we cant loop 6 times the code?
hokusaihokusai
Ok use the <apex:repeat tag.
mtbclimbermtbclimber

Or better yet, try apex:dataTable which iterates over a collection AND creates a table for you.

 

Also, don't do this:

 

<img id="theImage" src="https://na1.salesforce.com/servlet/servlet.FileDownload?file=01530000000mvyc" />

 

 Instead, do this:

 

 

<apex:image value="{!URLFOR($Action.Document.Download, docid)}"/>

 

 Where 'docid' is from your iteration. This ensures your image won't break if moved to another environment (e.g. na1 becomes na8) or if salesforce.com changes the endpoint for downloading files.

 

Finally, pasting record IDs into a page makes the page useless in other environments.  Any attempt to migrate such a page to an org without the same data (including the IDs) will break it and it will have to be fixed up manually.  Not to mention there is nothing preventing the doc from being deleted which would also break the link.  "hard coded" references like this are best left to Static Resources. 

 

Check out the Visualforce Developer Guide for more info on Static Resources, apex:dataTable, etc.