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
TechSteveTechSteve 

Note & attachments in vf page

Hi, if you open a standard page there is a related list called notes & attachments.

I want to show it on a visualforce page and cannot find out how anywhere in the documentation. 

I am a very new developer learning as I go. Could someone please help.

Sorry it is probably very easy but so much documentation and over 2hrs searching with no results!!

 

Thanks

 

Steve

shruthishruthi

I have given an example below. Hope it helps!

 

Name this page as: UsingStandardController

<apex:page standardController="Account">
<apex:detail relatedList="false"/>
<apex:relatedList list="Cases"/>
<apex:relatedList list="NotesAndAttachments"/>
</apex:page>

 

The Account with related list Cases & Notes And Attachments alone will appear on the VF Page [Given the link: https://ap1.salesforce.com/apex/UsingStandardController?id=AnyAccountId]

TechSteveTechSteve

Thanks for that but I had tried that. It produces nothing on the page at all.

I want the ability to upload scanned files that are related to a particular record and on a standard built in page this allows that with the attach button.

The page is based on a custom object using the standardcontroller for that page with an extension.

 

If I can I just want to add the notes and Attachment related list to my page but the normal <apex:relatedList list="notes & Attachments/> does not work.

 

Anyone any other ideas?

 

Thanks Steve

Devendra@SFDCDevendra@SFDC

 

 

Hi,

 

Please refer the below link.

 

http://www.forcetree.com/2011/02/upload-file-as-attachment-to-record.html

 

Hope it helps.

 

Regards,

Devendra S

shruthishruthi

Can you please post your code? Thereby, it will be easy to identify where and why any issue occurs.

TechSteveTechSteve

Hi, following the link above I have added :

     Public Attachment myfile;    

     Public Attachment getmyfile()    

      {

        myfile = new Attachment();        

        return myfile;    

      }       

      Public Pagereference Savedoc()    

      {

      String accid = System.currentPagereference().getParameters().get('cid');  

   

      Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);                 

 

      /* insert the attachment */  

             insert a;      

             return NULL;

      }   

 To my controller and then:

 // File upload to attachments for this record.
    Public Attachment myfile;
    Public Attachment getmyfile()
    {
        myfile = new Attachment();
        return myfile;
    }
  
    Public Pagereference Savedoc()
    {
        String accid = System.currentPagereference().getParameters().get('cid');

        Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body);
        
         /* insert the attachment */
         insert a;
        return NULL;
    }   

 

Then added the <apex:relatedlist list="NotesandAttachments"> to my page.

The file upload works but nothing is shown on the vf page the way I want it to but it is shown on the contact page.

I am carrying the contact record id as 'cid' in the url to display the contact on the page so I can see it is linking to that instead of the current record id. there is no record id in the url so I am a little stumped!!

 

So to recap: I want the file to attach to the current record and be displayed on the page I attached it to.

Later I will need to include this on another page as a history of things added, so is there a way to access what has been attached without the relate list?

 

Thank you for all your help.

 

Steve

TechSteveTechSteve

Hi as well as above I have tried changing

 

     String accid = System.currentPagereference().getParameters().get('cid'); 

TO

     String accid = ar.id ; (ar being a variable = to my custom object API)

 

But this just results in an error code:-

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Parent]: [Parent]
Class.AnnRevCon2.Savedoc: line 135, column 10 External entry point 

goabhigogoabhigo

Why don't you use standard Salesforce related list to attach the file, instead of writing that code given in forcetree blog?

 

As mentioned in above posts, use <apex:relatedList list="NotesAndAttachments"/> in your VF page.

 

Make sure that that custom object has Notes and Attachments related list present in its page layout.

TechSteveTechSteve

Thank you for your suggestion but as I said before, In have tried adding note & attachments to my page but it does not appear on the page. I have checked that I have added it to the custom object and have added it to the standard page layout but it still does not show on my vf page.

 

Any idea why?

 

Steve

goabhigogoabhigo

Can you please post the VF page code?

TechSteveTechSteve

Thanks here is my page:

 

<apex:page standardcontroller="SF36__c"  Tabstyle="Assessment__c" extensions="SF36Ext" sidebar="false" showHeader="false">
 <apex:form >
 <apex:image id="inslogo" url="{!$Resource.INSLogo}" width="120" height="57" />
   <apex:outputLabel ><b>{!$User.FirstName} {!$User.LastName}</b> is logged in.</apex:outputLabel>
   <div style="float:right"><apex:SectionHeader title="SF-36 Health Questionnaire ." ></apex:SectionHeader></div>
      <apex:pageBlock >         
        <apex:pageBlockTable value="{!Contacts}" var="o">       
            <apex:column value="{!o.name}"/>
            <apex:column value="{!o.Client_DOB__c}"/>
            <apex:column value="{!o.Contact_Ref__c}"/>
            <apex:column >
                <apex:facet name="header">DNR Status</apex:facet>
                   <script type="text/javascript">
                       if ({!o.DNR_Authorisation_Uploaded__c})
                       {
                           document.write("<div style=background-color:#ff0000><h1><center>DNR</center></h1></div>");
                       }
                           else
                       {
                           document.write("<center>CPR</center>");
                       }
                   </script>                   
            </apex:column>           
        </apex:pageBlockTable>   
    </apex:pageBlock>
     
    <apex:pageBlock >
        <apex:pageBlockButtons >
            <apex:commandButton value="new" action="/apex/SF36e{!conid}" />
            <apex:commandButton value="Back to assessments" action="/apex/Ax{!conid}"/>
        </apex:pageBlockButtons> 
    </apex:pageBlock>
     <apex:pageBlock >
        <apex:pageBlockTable value="{!SF36hist}" var="o">
            <apex:facet name="header">History of SF-36 Health Questionnaires</apex:facet>
            <apex:facet name="footer"><apex:pageBlockTable value="{!Contacts}" var="o"><apex:column value="{!o.name}"/></apex:pageBlockTable></apex:facet>    
                <apex:column headerValue="This Record Currently On View :">Currently Viewing... {!recid}</apex:column>
                <apex:column headerValue="Date This Record Was Created :"><apex:outputField value="{!o.CreatedDate}"/></apex:column>
                <apex:column headerValue="Record Number :"><apex:outputLink value="/apex/SF36?cid={!o.SF36Client__c}&rid={!o.name}">              
                <apex:outputField value="{!o.name}"/></apex:outputLink></apex:column>          
                <apex:column headerValue="Staff Member Who Created This Record :" ><apex:outputField value="{!o.CreatedByid}"/></apex:column>                               
        </apex:pageBlockTable>
       
     </apex:pageBlock>     
</apex:form>
<apex:relatedList list="NotesAndAttachments"/>
</apex:page>

khillan bhardwajkhillan bhardwaj
Hi Steve,
The relationship name for the Notes and Attachments related list has been changed in winter 14 release
you can show the attachement in the relatedlist tag

<apex:relatedList list="CombinedAttachments" subject="{!$CurrentPage.parameters.id}"/>

in the VF page if you are using Standard controller then there is no need to add subject attribute

Hop it will help you.
Thanks
Khillan Singh
Bryan Revelant 18Bryan Revelant 18
In case anyone else is reading this post, the reason why the notes and attachemets are not appearing is because the there is no ID. If you were to use the related list the record must be saved first then you can use the related list for attachements. As far as getting the attachements two display on the VF I have not been able to do this easily. 
nicksnicks
can you please paste successful vf and apex code?
I'm getting sObject error