+ Start a Discussion
apple_saeapple_sae 

How I can display my attachment ID in Visualforce page

Hi All,

I have query my attachment from my custom object using Relationship Queries,

 

but I don't know how I can display my attachment ID , I got error  Save error: Unknown property 'VisualforceArrayList.id' 

 

 I have queries and VF page like this:

 

public class documentCls {
	public Id uid;
	public Integer counter{get;set;}
	public list<Document__c> lstDocument{get;set;}
	public list<Document_Version__c> lstDocVs{get;set;}
	public list<Attachment> Attach{get;set;}
	public documentCls(){
		getlstDocument();
		getlstDocVs();	
	}
	
	public void getlstDocument(){
		uid = UserInfo.getUserId();
    	if(uid != ''){ 
    		lstDocument = [	SELECT	Document__c.Id,
	    				Document__c.Name,
	    				Document__c.Document_Name__c,
	    				Document__c.Description__c
	    			FROM	Document__c
	    			Where	Document__c.OwnerId = :uid];
	    					
	    	counter = [	SELECT 	Count()
	    			FROM	Document__c
	    			Where	Document__c.OwnerId = :uid];
	    				
	    	System.debug('My counted records: ' + counter);  
    	}  	
    }
     public void getlstDocVs(){
    	if(lstDocument.size() > 0){
    		for(Document__c d:lstDocument){
    			
    			lstDocVs = [SELECT	Document_Version__c.Id,
Document_Version__c.Document__r.Document_Name__c, Document_Version__c.Document__r.Description__c, Document_Version__c.Document__r.CreatedDate, Document_Version__c.Document__r.LastModifiedDate, (SELECT Attachment.Id
FROM Document_Version__c.Attachments) FROM Document_Version__c WHERE Document_Version__c.Document__c = :d.id ORDER BY Document_Version__c.Document__r.CreatedDate DESC]; } }else{ system.debug('Document is null'); } } }

 

<apex:page showHeader="false" standardStylesheets="false" sidebar="false" Controller="documentCls">
<div class="tab-pane" id="your-documents">
<div class="doc-alert">You have {!counter} new document ready for download!</div>
<apex:repeat value="{!lstDocVs}" var="v">
<ul class="doc-steps">
<li>
<apex:outputText value="{!v.Document__r.Document_Name__c}"/>
<apex:outputLink value="{!URLFOR($Action.Attachment.Download,Attachments.id)}" target="blank">
Preview
</apex:outputLink>
</li>
</ul>
</apex:repeat>
</div>
</apex:page>

 Thanks for any help

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Attachments is a related list on Document__c, so you can't treat it as though its a single instance.  I also think you need to prefix it with the var from your apex repeat.

 

I think you'll need to iterate the attachments in a similar way that you do the documents.  Something like:

 

 <apex:repeat value="{!lstDocVs}" var="v">
   <ul class="doc-steps">
    <li>
    <apex:outputText value="{!v.Document__r.Document_Name__c}"/>
    <apex:repeat value="{!v.Attachments}" var="att">
       <apex:outputLink value="{!URLFOR($Action.Attachment.Download,att.id)}" target="blank">
    </apex:repeat>

 

All Answers

bob_buzzardbob_buzzard

Attachments is a related list on Document__c, so you can't treat it as though its a single instance.  I also think you need to prefix it with the var from your apex repeat.

 

I think you'll need to iterate the attachments in a similar way that you do the documents.  Something like:

 

 <apex:repeat value="{!lstDocVs}" var="v">
   <ul class="doc-steps">
    <li>
    <apex:outputText value="{!v.Document__r.Document_Name__c}"/>
    <apex:repeat value="{!v.Attachments}" var="att">
       <apex:outputLink value="{!URLFOR($Action.Attachment.Download,att.id)}" target="blank">
    </apex:repeat>

 

This was selected as the best answer
apple_saeapple_sae

Hi bob,

 

Thank you for your reply, I have tried doesn't work I'm not get any error but Document Name and ID is disappear,

 

<apex:repeat value="{!lstDocVs}" var="v">
   <ul class="doc-steps">
    <li>
    <apex:repeat value="{!v.Attachments}" var="att">
       <apex:outputLink value="{!URLFOR($Action.Attachment.Download,att.id)}" target="blank">           
<apex:outputText value="{!v.Document__r.Document_Name__c}"/>
</apex:outputLink>
</apex:repeat>
</li>
</ul>
</apex:repeat>

Thanks,

Apple

bob_buzzardbob_buzzard

What does the rendered html look like?

apple_saeapple_sae

I got a blank page, nothing appear I try to do somethink like this and still not working, too.

<apex:repeat value="{!lstDocVs}" var="v">
   <ul class="doc-steps">
    <li>
    <apex:repeat value="{!v.Attachments}" var="att">
       <apex:outputText value="{!att.id}"/>
       <apex:outputLink value="{!URLFOR($Action.Attachment.Download,att.id)}" target="blank">           
         <apex:outputText value="{!v.Document__r.Document_Name__c}"/>
       </apex:outputLink>
    </apex:repeat>
   </li>
  </ul>
</apex:repeat>

 

bob_buzzardbob_buzzard

So if you view the source of the page, there is no HTML?

apple_saeapple_sae

Yes,I got this when view HTML source:

 <div class="tab-pane" id="your-documents">
   <ul class="doc-steps">
    <li>
   </li>
  </ul>
</div>

 

bob_buzzardbob_buzzard

Looking at your code this is entirely possible - you are only retrieving the last document in the list and its attachments.