+ All Categories
Home > Software > June SDG - Apex Best Practices

June SDG - Apex Best Practices

Date post: 12-Aug-2015
Category:
Upload: josep-vall-llovera
View: 225 times
Download: 1 times
Share this document with a friend
15
Apex Best Practices Josep Vall-llovera - CTO at Clapps 19/06/2015 @valnavjo Valnavjo in/jvn84 Valnavjo
Transcript
Page 1: June SDG - Apex Best Practices

Apex Best PracticesJosep Vall-llovera - CTO at Clapps

19/06/2015

@valnavjo Valnavjo in/jvn84 Valnavjo

Page 2: June SDG - Apex Best Practices

Introduction

2

Page 3: June SDG - Apex Best Practices

#1 Naming conventions

3

1. SF doesn’t provide packages to organize classes.2. Use naming conventions (English).

Page 4: June SDG - Apex Best Practices

#2 Singleton pattern

4

1. Same instance per execution request.2. Useful to avoid repeating unnecessary queries.

Page 5: June SDG - Apex Best Practices

#3 Util classes

5

1. Always use Singleton Pattern + Utils class.2. For example, Record Types.3. Do not query the same RT more than once.

Page 6: June SDG - Apex Best Practices

6

#4 Trigger Template1. Do not have more than one Trigger for the same

SObject.2. Salesforce doesn’t ensure the order of execution.3. Avoid chaos.

Page 7: June SDG - Apex Best Practices

7

#5 Bulkify1. All logic methods must be prepared to deal with

collections.

Page 8: June SDG - Apex Best Practices

#6 Group collections

8

1. Use Maps & Lists to group collections when bulkifying code.

Page 9: June SDG - Apex Best Practices

#7 Interfaces

9

1. Use interfaces when they are necessary.2. Focus on productivity.

Page 10: June SDG - Apex Best Practices

#8 Unit Tests

10

1. Unit Tests must be UNIT.2. Avoid @seeAllData = true (only for pricebooks).3. Use public class with @IsTest for data initialization.4. Just three things: prepare data, do test and assertions.

Page 11: June SDG - Apex Best Practices

#9 Use System.Limits1. Avoid governor limits.2. For example, when performing a search with SOSL.

11

Page 12: June SDG - Apex Best Practices

#10 Keep things simple

12

Logic

TriggerHandler

Utils

UI

API Helper

Trigger

Controller

Service

Unit Tests

Page 14: June SDG - Apex Best Practices

Code resources

https://github.com/Valnavjo/sdgbarcelona.git

14

Page 15: June SDG - Apex Best Practices

Thanks!

Q&A15


Recommended