3

I am looking to show the attached documents of custom objects record as a link in Pageblocktable.

Please help needed in directing.

2

Hi Arun SFDC, We can not directly query on NotesAndAttachment object. However we can query it when used as child query. If you want to show NotesAndAttachment of any custom object then you can make use of below code example. Here in my case I have used Country__c as a custom object. Controller Code:

public class CountryController {

    public Country__c country {get;set;}

    public CountryController(ApexPages.StandardController std){
        country = (Country__c)std.getRecord();
        populateNotesAndAttachments();
    }

    private void populateNotesAndAttachments(){
        if(country.Id != null){
            //Direct query on NotesAndAttachments is not supported, However you can get it in child query
            country = [Select Id,(Select Id, IsNote, Title From NotesAndAttachments) From Country__c WHERE Id = :country.Id];
        }
    }


}

VisualForce Page Code :

<apex:page standardController="Country__c" extensions="CountryController">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection title="Notes And Attachments">
                <apex:pageBlockTable  value="{!country.NotesAndAttachments}" var="noteOrAttachment"> 
                    <apex:column headerValue="Action">
                        <apex:commandLink target="_blank" action="/{!noteOrAttachment.Id}"  value="View"></apex:commandLink>
                    </apex:column>
                    <apex:column value="{!noteOrAttachment.Title}">
                    </apex:column>
                    <apex:column headerValue="Type">
                        <apex:outputText value="{!IF(noteOrAttachment.IsNote,'Note','Attachment')}"></apex:outputText>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page> 

Here is the standard page from which you could add/upload notes and attachments. enter image description here

Now here is the final visualforce page where you would be able to see your notes and attachments. enter image description here

I hope this helps you.

| improve this answer | |

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.