How to create an attachment object in apex?

How to create an attachment object in apex?

Heres my code. Am I missing out on anything here or is this just not the right way to create an attachment. I also pass the required parameters i.e. fileContents (this is a Base64 encoded string) and accountId (this is supposed to be the parentId for the attachment) Kindly advise.

When to use Base64 encoding in apex class?

The other day someone came to me and asked me how to Base64 encode some parameters in an Apex class. Base64 is often used when you need to encode binary data into characters. Base64 is a good way of taking binary data and turning it into text so that it can easily be transmitted in things like HTML form data and email.

How to create an attachment object in Salesforce?

Am I missing out on anything here or is this just not the right way to create an attachment. I also pass the required parameters i.e. fileContents (this is a Base64 encoded string) and accountId (this is supposed to be the parentId for the attachment) Kindly advise. That looks ok to me.

When to use ” before INSERT before update ” trigger?

Whenever a record is created by user (using New button on related list), “before insert before update” trigger validates a look up field to see if the value entered already exists in Salesforce (e.g. zip code).

How to display an error message in apex?

This will associate the error to the field, and it will highlight the field with red box and the error message underneath. The red text at the top (“Review all error messages…”) can’t be altered or removed. This allows users to know there’s an error, even if there’s many hundreds of fields on the page and they have to scroll down.

How to prepare a blob file in apex?

If the URL returned by this function is passed to APEX_UTIL.PREPARE_URL, ensure to set the P_PLAIN_URL argument to TRUE to ensure that no modal dialog code is being added, when the referenced page item is on a modal page. Name of valid application page ITEM that with type FILE that contains the source type of DB column.