What is Bulkification of code in Apex?

What is Bulkification of code in Apex?

The term bulkifying Apex code refers to the concept of making sure the code properly handles more than one record at a time. When a batch of records initiate Apex, a single instance of that Apex code is executed, but it needs to handle all of the records in that given batch.

What is trigger Bulkification?

Bulkified triggers operate on all sObjects in the trigger context. Typically, triggers operate on one record if the action that fired the trigger originates from the user interface. But if the origin of the action was bulk DML or the API, the trigger operates on a record set rather than one record.

Which is the best way to bulkify Apex code?

The following sections demonstrate the main ways of bulkifying your Apex code in triggers: operating on all records in the trigger, and performing SOQL and DML on collections of sObjects instead of single sObjects at a time. The SOQL and DML bulk best practices apply to any Apex code, including SOQL and DML in classes.

Which is best practice for bulk triggers in apex?

The SOQL and DML bulk best practices apply to any Apex code, including SOQL and DML in classes. The examples given are based on triggers and use the Trigger.New context variable. Let’s first look at the most basic bulk design concept in triggers. Bulkified triggers operate on all sObjects in the trigger context.

When to go for trigger in DML in apex?

Always go for bulkification.Instead of calling an DML operation on a single record,always opt for List of records. Most important thing is first check whether the same requirement can be achieved using a workflow rule,process builder,flows.If not then go for code i.e Trigger.

How often can a DML statement be called in bulk apex?

In this example, the update statement is inefficiently called once for each opportunity. If a bulk account update operation fired the trigger, there can be many accounts. If each account has one or two opportunities, we can easily end up with over 150 opportunities. The DML statement limit is 150 calls.