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
Devendra@SFDCDevendra@SFDC 

Customize Notes and Attachment

 

Hi,

 

How to customize Notes and Attachment section?Can we make visualforce pages to customize this functionality?

 

Regards,

Devendra

Best Answer chosen by Admin (Salesforce Developers) 
sdetweilsdetweil

come on now, there must be a 100 samples in the VF section, and the VF reference has some good ones too..

I consider myself to be rookie here.. I do great with system level code and struggle with UI. the SF code is easy to learn

and pretty functional.. I can do a lot with a little bit of code.. lots less than any other platform I have ever used over the years.

 

SF uses the Model View Controller presentation model.. this separates the data from the UI.

 

so VF pages cannot directly access data, they must go thru apis into a controller (apex class) that accesses the database.

 

in your apex class you define variables that will hold the data, and access those variables from the VF page

you use the get/set attributes, like you did to define how the variables are accessed..

 

now you just need to decide how u want to present the data in the UI..  I'll provide a table type view ,you can change to something else later

 

in VF you define a 'page' and connect it to the class which is the data access controller, (you can chain multiple classes too)

Then u use the VF tags to define, like HTML, how the page should look. the VF language provides attributes to connect to the data.

Here the 'value' attribute of the pageblocktable tag references the controller variable name.

This tag is a loop mechanism and will render all the elements of the variable. the var= gives your page program a local name.

You need to know the format (fields) in the variable structure.. in your case n1 is a Note. you can look up its field names.  it has a title and a body field at least.

 

so this little page, renders all the Notes found for a particular parent, in a two column arrangement.  with column titles over the two columns.

 

the controller class should prepare some data on construction, so for this example, your code should be called from the controllers constructor.. there are lots of other ways too.

<apex:page controller="controller_class_name">
<apex:form >
 <apex:pageblock>
 <apex:pageblocktable value="{!n1}" var="a">
     <apex:column value="{!a.Title}" headerValue="Title"/>     
    <apex:column value="{!a.Body}" headerValue="Body"/>  
 </apex:pageblocktable>
</apex:pageblock>
</apex:form>
</apex:page>

 

 

 

 

 

All Answers

hemantgarghemantgarg

Yes, you can fetch the notes and attachment related list into apex (write your own logic) and display on a custom vf page, then you can add this page as an inline vf apge on he page layout.

 

Thanks

Hemant

Devendra@SFDCDevendra@SFDC

 

Hi Hemant,

 

How to fetch notes and attachment list into apex?

 

Regards,

Devendra S

 

 

sdetweilsdetweil

notes and attachments are 1st class objects.. so

 

list<notes> nl = [select id, name, body from note where parentid=:object_parent];

 

Sam

Devendra@SFDCDevendra@SFDC

 

Hi sdetweil,

 

As per your suggestion, I have written apex code to retrive notes and atachment.

 

 

public LIST<Note> n1{get;set;}

public LIST<Attachment> n2{get;set;}

 

String strid=System.currentPagereference().getParameters().get('id');

 

 n1 = [select id, title, body from note where parentid=: strid];

 n2 = [select id, Name from Attachment where parentid=:strid];

System.debug(+n1);

System.debug(+n2);

 

It is showing values in debug also.

 

But how to display these retrieved items on visualforce page??

 

Thanks and Regards,

Devendra S

sdetweilsdetweil

come on now, there must be a 100 samples in the VF section, and the VF reference has some good ones too..

I consider myself to be rookie here.. I do great with system level code and struggle with UI. the SF code is easy to learn

and pretty functional.. I can do a lot with a little bit of code.. lots less than any other platform I have ever used over the years.

 

SF uses the Model View Controller presentation model.. this separates the data from the UI.

 

so VF pages cannot directly access data, they must go thru apis into a controller (apex class) that accesses the database.

 

in your apex class you define variables that will hold the data, and access those variables from the VF page

you use the get/set attributes, like you did to define how the variables are accessed..

 

now you just need to decide how u want to present the data in the UI..  I'll provide a table type view ,you can change to something else later

 

in VF you define a 'page' and connect it to the class which is the data access controller, (you can chain multiple classes too)

Then u use the VF tags to define, like HTML, how the page should look. the VF language provides attributes to connect to the data.

Here the 'value' attribute of the pageblocktable tag references the controller variable name.

This tag is a loop mechanism and will render all the elements of the variable. the var= gives your page program a local name.

You need to know the format (fields) in the variable structure.. in your case n1 is a Note. you can look up its field names.  it has a title and a body field at least.

 

so this little page, renders all the Notes found for a particular parent, in a two column arrangement.  with column titles over the two columns.

 

the controller class should prepare some data on construction, so for this example, your code should be called from the controllers constructor.. there are lots of other ways too.

<apex:page controller="controller_class_name">
<apex:form >
 <apex:pageblock>
 <apex:pageblocktable value="{!n1}" var="a">
     <apex:column value="{!a.Title}" headerValue="Title"/>     
    <apex:column value="{!a.Body}" headerValue="Body"/>  
 </apex:pageblocktable>
</apex:pageblock>
</apex:form>
</apex:page>

 

 

 

 

 

This was selected as the best answer
Devendra@SFDCDevendra@SFDC

 

Hi sdetweil,

 

Thank you so much..!!

 

Cheers,

Devendra S

sfdc2090sfdc2090

Can we pass values to notes related list from salesforce?

 

Appreciate your help

 

Thanks

Rama Krishna.ax1900Rama Krishna.ax1900

Hi sdetweil,

how to display the both n1 & n2 in one pageBlockTable