Attachments in Salesforce

Salesforce attachment represents a file that a User has uploaded and attached to a parent standard or custom object record.

If the user has create permission on a parent object, then only he/she can able to attach an attachment to the parent object.

Attachment can support following calls :

create(), delete(), describeSObjects(), getDeleted(), getUpdated(), query(), retrieve(), search(),undelete(), update(), upsert()

Notes and Attachments are available for Standard Controller by default.If it is not there you can adding it in a Page Layout related list and for custom object you have to enable Add Notes and Attachments related list to default page layout as shown below.

This above option will be only available when custom object is first created.If you wish to add/remove Notes and Attachment later you can add/remove it to related list at any time by using page layout.

Attachments Fields :

Field Name Data Type Description
Body base64 Required. Encoded file data.
BodyLength integer Size of the file (in bytes).
ConnectionReceivedId reference ID of the PartnerNetworkConnection that shared this record with your organization. This field is only available if you have enabled Salesforce to Salesforce.
ConnectionSentId reference ID of the PartnerNetworkConnection that you shared this record with. This field is only available if you have enabled Salesforce to Salesforce. 
ContentType string The content type of the attachment.

If the Don't allow HTML uploads as attachments or document recordssecurity setting is enabled for your organization, you cannot upload files with the following file extensions: .htm, .html, .htt, .htx, .mhtm, .mhtml,.shtm, .shtml, .acgi, .svg.

Description textarea Description of the attachment. This field is available in API version 18.0 and later.
IsEncrypted boolean Indicates whether the attachment is encrypted using Platform Encryption(true) or not (false).
IsPartnerShared boolean Indicates whether this record is shared with a connection usingSalesforce to Salesforce. Label is Is Shared With Partner.
IsPrivate boolean Indicates whether this record is viewable only by the owner and administrators (true) or viewable by all otherwise-allowed users (false). 
Name string Required. Name of the attached file. Label is File Name.
OwnerId reference ID of the User who owns the attachment.
ParentId reference Required. ID of the parent object of the attachment.

Access to fields depends on the method being used:

  1. All of the fields are accessible using the describeSObjects() and query() calls. With thecreate() call, you can insert the Name, ParentId, Body, IsPrivate, and OwnerId fields.
  2. To modify existing records, the update() call gives you access to change the Name, Body,IsPrivate, and OwnerId fields.
  3. You can access all of the fields using a query() call. However, you can't receive the Body field for multiple records in a single query() call. If your query returns the Body field, your client application must ensure that only one row with one Attachment is returned; otherwise, an error occurs. A more effective approach is to return IDs (but not Attachment records in theBody field) from a query() call and then pass them into retrieve() calls that return the Bodyfield.
  4. For information about accessing the attachments of archived activities, see Archived Activities.

Limitation of Attachments :

  1. Attachment maximum size that can be upload is 25 MB.
  2. For a file attached to a Solution, the limit is 1.5 MB.
  3. The maximum email attachment size is 3 MB.
  4. The size limit for multiple files attached to the same email is 25 MB, with a maximum size of 5 MB per file.
  5. The query call does not return attachments parented by email, unless the user performing the query has the “Modify All Data” permission.
  6. Attachment records are not searched during text searches.
  7. When issued by an administrator, the query results include Attachment records from the Recycle Bin.
  8. When issued by a non-administrator, the queryAll() call results do not include Attachment records from the Recycle Bin.
  9. You can create trigger for Attachment only by using developer console or Force IDE. Form Setup you can't able to create a trigger for attachment.
  10. By Using global $Action you can only able to download a file.For Attachment $Action will not support for Create(New) / Update(Edit) / View.
  11. You can't able to customize Notes and Attachment related list.If you want then go with Visual page replacing with standard Notes and Attachment related list.
  12. You can't able to create custom fields for Notes and Attachments.
  13. Export attachments using Data Loader will give you file body as binary encrypted format.So you will face some problem while import it back.But you can use dataloader,io to import and export salesforce attachment.

If you have a any suggestions please let me know in comments.

Have a good day smiley

    Rating: 
    No votes yet