+ Start a Discussion
samrat.1985@lntinfotechsamrat.1985@lntinfotech 

Notes And Attachments on Visual Force Page

I have a requirement of showing Notes & Attachments on my visual force page. Like it is shown on the accounts tab.

 

Best Answer chosen by Admin (Salesforce Developers) 
JasonH_AllerganJasonH_Allergan

sure if its entirly what you are looking for but this is what i have curently got.!

 

 

 

<apex:page standardController="Custom_Object__c" tabStyle="Custom_Object__c">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />   
    <style>
        .activeTab {background-color: #236FBD; color:white; background-image:none}
        .inactiveTab {background-color: lightgrey; color:black; background-image:none}
        .br {mso-data-placement:same-cell;}
    </style>
 </head> 
    <apex:tabPanel switchType="client" selectedTab="tabNotes" id="CustomObjectTabPanel" tabClass="activeTab" inactivetabClass="inactiveTab">          
        <apex:tab label="Notes" name="Notes" id="tabNotes">           
            <apex:form >
                <apex:pageBlock title="Notes">
                    <apex:pageBlockTable value="{!Custom_Object__c.Notes}" var="note">
                        <apex:column value="{!note.createddate}" width="120px"/>
                        <apex:column value="{!note.createdbyid}" width="120px"/>
                        <apex:column value="{!note.body}" />
                    </apex:pageBlockTable>
                    <apex:pageBlockButtons location="top">
                        <apex:commandbutton value="Add Comment" action="/002/e?parent_id={!LEFT(Custom_Object__c.Id,15)}&retURL=%2Fapex%2FCustom_Object%3Fid%3D{!Custom_Object__c.Id}"/>
                    </apex:pageBlockButtons>
                </apex:pageBlock>
            </apex:form>
        </apex:tab>
    </apex:tabPanel>
</apex:page>

 

 

This is not using a relatedList and will display just notes not attachments - the command button is a "New Note" Button.

All Answers

samrat.1985@lntinfotechsamrat.1985@lntinfotech

Ok fellas i was able to achieve that... but then again the requirement changed.

 

Now instead of it being a related list. i.e Notes and attachments being a related list. I want it or the requirement is to have it  on a page block with othere tabs i.e independent without being in the related list.

 

Now can anyone help.

JasonH_AllerganJasonH_Allergan

sure if its entirly what you are looking for but this is what i have curently got.!

 

 

 

<apex:page standardController="Custom_Object__c" tabStyle="Custom_Object__c">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />   
    <style>
        .activeTab {background-color: #236FBD; color:white; background-image:none}
        .inactiveTab {background-color: lightgrey; color:black; background-image:none}
        .br {mso-data-placement:same-cell;}
    </style>
 </head> 
    <apex:tabPanel switchType="client" selectedTab="tabNotes" id="CustomObjectTabPanel" tabClass="activeTab" inactivetabClass="inactiveTab">          
        <apex:tab label="Notes" name="Notes" id="tabNotes">           
            <apex:form >
                <apex:pageBlock title="Notes">
                    <apex:pageBlockTable value="{!Custom_Object__c.Notes}" var="note">
                        <apex:column value="{!note.createddate}" width="120px"/>
                        <apex:column value="{!note.createdbyid}" width="120px"/>
                        <apex:column value="{!note.body}" />
                    </apex:pageBlockTable>
                    <apex:pageBlockButtons location="top">
                        <apex:commandbutton value="Add Comment" action="/002/e?parent_id={!LEFT(Custom_Object__c.Id,15)}&retURL=%2Fapex%2FCustom_Object%3Fid%3D{!Custom_Object__c.Id}"/>
                    </apex:pageBlockButtons>
                </apex:pageBlock>
            </apex:form>
        </apex:tab>
    </apex:tabPanel>
</apex:page>

 

 

This is not using a relatedList and will display just notes not attachments - the command button is a "New Note" Button.

This was selected as the best answer
JasonH_AllerganJasonH_Allergan

During the 5 minutes it took to write that last post i managed to think of a way around the edit button.

 

I added an aditional column and put this in

 

 

<apex:column HeaderValue="Edit"><a href="/{!LEFT(note.id,15)}/e?&retURL=%2Fapex%2FCustom_Object%3Fid%3D{!Customer_Obeject__c.Id}">Edit</a></apex:column>

 

This will edit the note and also then return you to the record you were view before.

samrat.1985@lntinfotechsamrat.1985@lntinfotech

Thanks Jason,

 

Well would be greatful if you can explain part by part what have you written in the action property of the of the command button. So that i could understand and change it accordingly. Please

JasonH_AllerganJasonH_Allergan

Would be happy to

 

<apex:commandbutton value="Add Comment" action="/002/e?parent_id={!LEFT(Custom_Object__c.Id,15)}&retURL=%2Fapex%2FCustom_Object%3Fid%3D{!Custom_Object__c.Id}"/>

 

 

Value="Add Comment"

Text that apears on the button

 

="/002/e?parent_id={!LEFT(Custom_Object__c.Id,15)}

This opens up the new note related to the record (Parent_ID). Now normally when you put in Custom_Object__c.ID into a link you will get an extra 3 characters (18 in total) added to the ID which make the link fail. The statment {!LEFT (xxxx, 15)} tells the object you are calling to limit the results to 15 characters off the end. I have not tried this but im guessing if you put RIGHT it would take the 3 chars off the start.

 

e.g

record ID = a0m20000000UtSU

record ID in Link = a0m20000000UtSUAA0

 

&retURL=%2Fapex%2FCustom_Object%3Fid%3D{!Custom_Object__c.Id}"/>

This is a simple URL return. When you have saved the note you will be taken back to the record you were creating the note for.

the urlbreakdown looks more like this when not in code.

 

Here is where my understanding is a little guess work

%2F   =    /

%3F   =    .

%3D   =   =

 

so you end up with this.

 

&retURL=/apex/Custom_Object?id={!Custom_Object__c.Id}

 

 

Obviously I have put in Custom_Object__c because the code i wrote was for a Custom_Object. If this was for accounts you would just replace it with "Account"

 

hope this helps! :D

samrat.1985@lntinfotechsamrat.1985@lntinfotech

Hey thanks again Jason. Great explanation.

 

I was able to make it work based on my custom object.

But now the requirement again changed.

I want it to work on custom controller independently where the parent id will come from a webservice.

Based on my past experience of coding i tried out to make it work but was not able to do so.

I there a possibility to make the notes work using custom controller on a VF page where the id is coming from an external web service??

JasonH_AllerganJasonH_Allergan

I would like to help but sadly that goes a little beyond my knowledge of coding -

 

I would hazard a guess that you would need to create a Apex Class to handle some of the connections :S - sorry buddy.

 

Jason

samrat.1985@lntinfotechsamrat.1985@lntinfotech

Thanks again.

Well i have a complete application workin using webservice so thats not a problem. If u need anything regarding working with webservice u can cantact.

 

But this new requirement is making me struggle a lot. will try to find out and if or when i get an answer will keep u updated. thansks for your help

goabhigogoabhigo

Thanks guys.