Contents
What is bulkification?
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.
How to bulkify your code?
Bulkify your code by combining SOQL queries
- Create a Set of all potential values you need to query against. – In this chapter’s trigger, this means every possible value of newCase.SuppliedEmail.
- Query against all records needed in Step 1 using a single SOQL query. – Always do this before entering the loop!
Can we call future method from triggers?
Interviewer: Can I write a future call in Trigger? Interviewee: Yes, you can. Interviewer: So, consider a case, I have Written a future call in the Account’s trigger update operation. and I have a batch job running on Account records and does DML on them.
Is there a problem with trigger bulkification in apex?
There are a few things that jump out that might be a problem. All this logic is buried in a trigger and is not reusable. It is very tough to test a specific piece of logic in the trigger. You basically have to call a DML statement to trigger the entire trigger. So how do we fix that?
Which is the best trigger pattern in apex?
Here’s a link to the Trigger Pattern for Tidy, Streamlined, Bulkified Triggers which is a good place to start if you’d like to implement your triggers as classes and have any and all code for for a single object in one trigger; something which I believe is very important to do whenever possible.
Which is the best way to bulkify in Salesforce?
The first and easiest way to ‘ BULKIFY ‘ is to leverage collections in order to save yourself SOQL calls and DML statements. Here’s an older, but still great resource by Jeff Douglass on utilizing collections in Salesforce.
How to create general triggers in Salesforce.com?
Lets assume you have two specific pieces of business logic that you need to apply after an account is created. The easy way to accomplish this would be to create 2 triggers on the account object. This could work well depending on your situation. What if you have logic in trigger2 that is dependent on the outcomes of trigger1?