I have a visualforce page using an apex:repeat tag like this :

<apex:page applyBodyTag="false" applyHtmlTag="false" sidebar="false" showHeader="false" renderAs="pdf" standardcontroller="Quote" extensions="DevisPDFController" action="{!savePDF}">                     
<apex:repeat value="{!Quote.QuoteLineItems}" var="item" >
                             <td class="lignesPrix" style="width:60%;max-width:60%; border-left:0px;"><apex:outputText value="{!item.Product2.name}"/></td>
                             <td class="lignesPrix" style="text-align: right;"><apex:outputText value="{!item.Prix_de_vente_HT_unitaire__c} €"/></td>
                             <td class="lignesPrix" style="text-align: right;" ><apex:outputText value="{!item.Quantity}"/></td>
                             <td class="lignesPrix" style="text-align: right;" ><apex:outputText value="{!item.Prix_de_vente_HT_total__c} €"/></td>
                             <td class="lignesPrix" style="text-align: right;" ><apex:outputText value="{!item.Prix_de_vente_TTC_total__c} €"/></td>

In my apex controller (it's an extension) I have that :

public class DevisPDFController {
public Quote devisItem{get;set;} 
public string idVal{get;set;} 
public string doSave{get;set;} 
public List<QuoteLineItem> lLignesDevis{get;set;}

public DevisPDFController(ApexPages.StandardController stdController){ 
    idVal = stdController.getId(); 
    System.debug('### idVal : ' + idVal);
    doSave = ApexPages.currentPage().getParameters().get('doSave'); 
    devisItem = [Select ID, Name, OpportunityId, QuoteNumber, lastmodifieddate From Quote where ID = :idVal]; 
    lLignesDevis = [SELECT Id, Prix_d_achat_HT_unitaire__c, Prix_de_vente_HT_total__c, Prix_de_vente_TTC_total__c, 
                    Quantity, Product2Id, Product2.Name, Product2.ProductCode, Prix_de_vente_HT_unitaire__c, product2.family
                    FROM QuoteLineItem 
                    WHERE QuoteId = :idVal 
                    ORDER BY Product2.ProductCode ];


public pageReference savePDF(){ 
    if(doSave == 'No'){ 
        return null; 
    PageReference pagePdf = new PageReference('/apex/DevisPDF'); 
    pagePdf.getParameters().put('id', idVal); 
    pagePdf.getParameters().put('doSave', 'No'); 

    Blob pdfPageBlob;
    pdfPageBlob = pagePdf.getContentAsPDF();

    Attachment a = new Attachment(); 
    a.Body = pdfPageBlob; 
    a.ParentID = idVal;
    a.Name = 'Devis : ' + devisItem.QuoteNumber + '.pdf';
    a.Description = devisItem.name;
    insert a; 

    return new PageReference('/' + idVal); 


I tried to use the order by in my query, but it doesn't work; my items are not sorted by the Product2.ProductCode field.

Is there a way to do that ? It's a VF page used in PDF with a standard controller and an extension (with the code above)

  • 1
    With the code provided it is difficult to pinpoint the issue. You have Quote.QuoteLineItems being iterated upon in your VF but I don't see it assigned in your Apex. It doesn't appear you're referencing the same things. Furthermore, I can't think of any reasons why the ORDER BY clause wouldn't be sorting - though it may not be sorting in a way that you desire (e.g. sorting numbers like 1,10,11,2,20). There isn't any way to sort this data once it's on the VF page, so I would focus on sorting either in the SOQL query or by using a sort() method.
    – nbrown
    Commented Jun 2, 2020 at 15:40
  • @nbrown I have updated my code so there is more to check. The field Product2.ProductCode is a letter and a number for each product (for example A001, A002, B001, B002, B003) so in theory all the code with A should be together, and so on and the codes with B should be displayed after the A, etc but it does't work
    – dou
    Commented Jun 2, 2020 at 15:45
  • see Ideasforce's answer. You need to reference the variable you're assigning the sorted QuoteLineItems to, lLignesDevis
    – nbrown
    Commented Jun 2, 2020 at 18:48

1 Answer 1


In your VF code you are passing the record from standard controller Quote as value for your apex:repeat, you should use your custom collection llignesDevis instead.

Change this:

<apex:repeat value="{!Quote.QuoteLineItems}" var="item" >

for this:

<apex:repeat value="{!lLignesDevis}" var="item" >

You must log in to answer this question.

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