0

I have the following feature request:

On the opportunity level I want to see all pdfs from all quotes from that very opportunity. So I think (hopefully) this is something Apex can do for me.

As I am not much of a developer I was thinking I need something like:

ListOfPDFs = [SELECT Id, ... FROM Quote (SELECT Id,... FROM QuotePDF) WHERE Opportunity.Id = currentOpportunity

In the end I want to display it as a simple table in visualforce.

Any advice is appreciated

Thanks a lot!


Edit:

This is what my code looks like now:

public class QuoteList {

public Opportunity currentOpp {get;set;}
public List<Quote> quotes  {get;set;} 
public List <QuoteDocument> documentRecord  {get;set;}    

 public QuoteList(ApexPages.StandardController stdController) {
 currentOpp  = [SELECT Id FROM Opportunity WHERE ID =: 
 stdController.getID()];
 }

 public PageReference getPdfs() {         

 quotes = [SELECT Id,Name,(SELECT Id FROM QuoteDocuments)FROM Quote WHERE 
 OpportunityId = :currentOpp.id];
 
 for(Quote record: quotes) {
 for(QuoteDocument documentRecord: record.QuoteDocuments) {
System.debug('pdfid'+documentRecord.id);
 }
}     
 

 return null;
 }
 }

This is my vf page:

<apex:page standardcontroller="Opportunity" extensions="QuoteList" docType="html-5.0" lightningStylesheets="true" action="{!getPdfs}"> 

<apex:form>
<apex:repeat value="{!quotes}" var="pdf">
    
    <apex:outputText value="{!pdf.Id}"/>
</apex:repeat>
</apex:form>
</apex:page>

Unfortunately I have still no clue how to show values of the QuoteDocument in my page. All am I able to do is to access the quotes :(

2 Answers 2

2

It should be:

Quote[] quotes = [SELECT Id, ...,
  (SELECT Id, ... FROM QuoteDocuments)
FROM Quote
WHERE OpportunityId = :currentOpportunity];

You'll need to iterate over each quote, then get the values from each item in QuoteDocuments:

for(Quote record: quotes) {
  for(QuoteDocument documentRecord: record.QuoteDocuments) {
    // Do stuff here //
  }
}
0

I have played around a bit and this is my best solution so far:

class:

public class QuoteList {

public Opportunity currentOpp {get;set;}
public List<Quote> quotes  {get;set;} 

public QuoteList(ApexPages.StandardController stdController) {
 currentOpp  = [SELECT Id FROM Opportunity WHERE ID =: stdController.getID()];
 }

 public PageReference getPdfs() {         

 quotes = [SELECT Id,Name,(SELECT Id,Name,ContentVersionDocumentId,QuoteId FROM 
 QuoteDocuments)FROM Quote WHERE OpportunityId = :currentOpp.id];


  return null;
  }
  }

visualforce page:

<apex:page standardcontroller="Opportunity" extensions="QuoteList" 
 lightningStylesheets="true" action="{!getPdfs}">  
   
   <apex:form >
    <apex:pageBlock >
     <apex:pageBlockSection >
      <apex:repeat value="{!quotes }" var="quote">
       <apex:repeat value="{!quote.QuoteDocuments}" var="pdf" >
     <!--     <apex:outputField value="{!pdf.id}" />-->
        
        <apex:outputField value="{!pdf.ContentVersionDocumentId}" /> 

        
        <a href="/{!pdf.ContentVersionDocumentId}">
        {!pdf.Name}
        </a>
        
    </apex:repeat> 
  </apex:repeat>
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
 </apex:page>

For reasons I don't understand <apex:outputField value="{!pdf.ContentVersionDocumentId}" /> is directly creating a link. Which is actually what I want in the end but it has some weird behaviour when opening it in a new tab. In addition to that there seems to be a problem with the "name" when I create my quotes via a flow where the names are being defined.

enter image description here

You must log in to answer this question.

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