Common Apex Mistakes
In this chapter, we will cover common mistakes made when writing Apex code and the appropriate defensive programming techniques to avoid them. Before we begin to move into more advanced topics within the Apex language, it is important that first we ensure a common grounding by removing any common errors within our code. For some of you, this material may simply be a refresher or a reiteration of some practices. In general, these mistakes form the basis of many of the common exceptions and errors that I have seen in my time working with the Salesforce platform and so are worth addressing upfront. By the end of this chapter, you will hopefully be more aware of when these mistakes may occur within your code and be able to develop in a defensive style to avoid them.
In this chapter, we will cover the following topics:
- Null pointer exceptions
- Bulkification of Apex code to avoid governor limits
- Hardcoding references to specific object instances
- Patterns to deal with managing data across a transaction