Add Attachment to Record Using Custom Controller in Visualforce

Add Attachment to Object record Using Custom Controller in Visualforce

Adding Attachment to a custom object in Visualforce involves the following steps:

Step 1: If you have not created the object in your Salesforce org, then create the object.

Step 2: Create the necessary fields because there are Use Cases at times where you need to enter information before uploading your attachment.

Step 3:  Add the Notes and Attachments Related List to the object Page Layout and save.

To learn more about Standard or custom object Page Layout customization in Salesforce, check this  link

Step 4: Write both the Visualforce and Controller codes for the functionality

For this post, the custom object I created is Bank with Bank__c as the API name. The User Interface before I click upload or Save button is attached below

Click the Upload button and then go to the object, click it to display the recent records. The record you have just created should be number one on the list. Click this record to go to its Edit page. Yoe will see the Notes and Attachments link counter has changed if the record is not a newly created one. However, for this post, it is a new record and the counter indicates one attachment I have just uploaded. Below is the Page

Below is the Visualforce code for the above

The Controller is attached below

If you have any question, sent me an email

Thanks for visiting

 

This Post Has One Comment

  1. i have a question?

    when i select a checkbox value in vf page the selected value or attachment to get inserted in an object.i need a controller logic.
    please help me…

Leave a Reply

Close Menu