APEX WORKBOOK ALL CONTENT WITH COMPLETESOLUTIONS
Apex Workbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Part 1: Orientation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Creating Warehouse Custom Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Using the Developer Console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Activating the Developer Console . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Using the Developer Console to Execute Apex Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Creating Sample Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Creating and Instantiating Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Creating an Apex Class Using the Developer Console . . . . . . . . . . . . . . . . . . . . . . . . . 6 Calling a Class Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Creating an Apex Class Using the Salesforce User Interface . . . . . . . . . . . . . . . . . . . . . 9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Part 2: Apex Language Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Primitive Data Types and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Boolean and Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Time, Date, and Datetime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Integer, Long, Double and Decimal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Null Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Enums . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Comments, Case Sensitivity, Collections and Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Case Sensitivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Arrays and Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Sets and Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Classes, Interfaces and Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Defining Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Private Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Static Variables, Constants, and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Property Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 sObjects and the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 What is an sObject? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 SOQL and SOSL Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Traversing and Querying sObject Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 SOQL For Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Apex Data Manipulation Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 What Is an Exception? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Try, Catch, and Finally Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Built-In Exceptions and Common Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 Catching Different Exception Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Creating Custom Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 Part 3: Apex in Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Executing Data Operations as a Single Transaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Adding Custom Business Logic Using Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Creating a Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Invoking the Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Apex Unit Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Adding a Test Utility Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Add Test Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Run Tests and Code Coverage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Running Apex Within Governor Execution Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Scheduled Execution of Apex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Adding a Class that Implements the Schedulable Interface . . . . . . . . . . . . . . . . . . . . . 58 Adding a Test for the Schedulable Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Scheduling and Monitoring Scheduled Jobs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Apex Batch Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Adding a Batch Apex Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Adding a Test for the Batch Apex Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Running a Batch Job . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Apex REST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Add a Class as a REST Resource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Creating a Record Using the Apex REST POST Method . . . . . . . . . . . . . . . . . . . . . . . . . 68 Retrieving a Record Using the Apex REST GET Method . . . . . . . . . . . . . . . . . . . . . . . . . 69 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Visualforce Pages with Apex Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Enabling Visualforce Development Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Contents Creating a Simple Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Displaying Product Data in a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 Using a Custom Apex Controller with a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . 75 Using Inner Classes in an Apex Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Adding Action Methods to an Apex Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Contents APEX WORKBOOK FApex is a strongly-typed, object-oriented programming language that allows you to write code that executes on the F platform. Out of the box, F provides a lot of high-level services, such as Web services, scheduling of code execution, batch processing, and triggers—all of which require you to write Apex. About the Apex Workbook This workbook provides an introduction to both the Apex programming language, as well as the contexts in which you can use Apex—such as triggers. This workbook does assume you know a little about programming. If you don’t, you’ll still manage to follow along, but it will be a little more difficult. We recommend Head First Java to start learning about programming. Although the book is about Java, Java is quite similar to Apex in many ways, and it will provide the foundation you need. The workbook is organized into three chapters: • Part 1: Orientation shows you the basics: how to create a simple Apex class, and how to use the Developer Console to execute Apex snippets. • Part 2: Apex Language Fundamentals looks at the syntax, type system, and database integration found in the Apex language. • Part 3: Apex in Context looks at how to use Apex to write triggers, unit tests, scheduled Apex, batch Apex, REST Web services, and Visualforce controllers. The goal is to give you a tour of Apex, not build a working application. While touring along, feel free to experiment. Change the code a little, substitute a different component—have fun! Intended Audience This workbook is intended for developers new to the F platform who want an introduction to Apex development on the platform, and for Salesforce admins who want to delve more deeply into app development using coding. If you’re an admin just getting started with F, see the F Platform Fundamentals for an introduction to point-and-click app development. Supported Browsers Microsoft Edge Salesforce supports Microsoft Edge on Windows 10 for Salesforce Classic. Note these restrictions. • The HTML solution editor in Microsoft Edge isn’t supported in Salesforce Knowledge. • Microsoft Edge isn’t supported for the Developer Console. • Microsoft Edge isn’t supported for Salesforce CRM Call Center built with CTI Toolkit version 4.0 or higher. Before You Begin You’ll need a F environment that supports F development. Th
Written for
- Institution
-
Liberty University
- Course
-
COMPUTER S 611
Document information
- Uploaded on
- September 3, 2023
- Number of pages
- 87
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
apex workbook all content with completesolutions