1 / 47

@archladies archladies

@archladies archladies.com. PLATFORM DEVELOPER I Certification Study Group Week 4 Led by: Blanca V. Leon-Carter bvleoncarter@gmail.com. #LBAjourneytoPD1. Guest Presenter. Development Manager & Solution Architect 2 x Salesforce Certified Former SQL Developer.

rubys
Download Presentation

@archladies archladies

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. @archladiesarchladies.com PLATFORM DEVELOPER ICertification Study Group Week 4Led by: Blanca V. Leon-Carter bvleoncarter@gmail.com #LBAjourneytoPD1

  2. Guest Presenter • Development Manager & Solution Architect • 2x Salesforce Certified • Former SQL Developer Study Group MemberKelsey Shannon@kelseypshannon

  3. Week 4 Objectives Logic & Process Automation {part 2} • Describe how to programmatically access and utilize the object schema. • Describe how to use and apply Apex control flow statements • Describe how to write and when to use Apex classes and interfaces • Describe how to use basic SOSL, SOQL, and DML statements when working with objects in Apex • Describe the basic patterns used in triggers and classes to process data efficiently • Describe when to use and how to write triggers • Describe the relationship between Apex transactions, the save order of execution, and the potential for recursion and/or cascading • Describe how to implement exception handling in Apex • Describe how to write Visualforce controllers • Describe when and how to use standard Visualforce controllers vs Apex custom controllers and controller extensions • Describe the programmatic techniques to prevent security vulnerabilities in Apex and Visualforce • Describe how Apex impacts the ability to make declarative changes

  4. MVC Development • Model View Controller (MVC) is a software architecture pattern • Model - database schema & objects • Objects, Fields, and Relationships • View - how schema is presented • Visualforce pages, page layouts, tabs • Controller - provide instructions on how the interface should act • Workflows, Apex Classes, Triggers Source: Model View Controller

  5. Apex

  6. Defining an Apex Class • Outer Class structure: • Access modifier + Sharing Mode + <class> + Class Name + Interfaces + Extensions Source: Apex Class Definition

  7. Adding a Method • Method structure: • Access modifier + Data Type + Method Name + Parameters Source: Apex Class Definition

  8. Collections • Lists (Arrays) - Ordered collection of elements • Set - Unordered collection of elements that do not contain duplicates • Maps - Collection of key-value pairs • Use when you need identifiers or keys like IDs and Names Source: Salesforce Collections

  9. Control Structure • Three ways to control the flow of code: • IF/ELSE statements • Switch Statements • Loops

  10. Control Structure - IF ELSE • IF - Executes if a boolean statement evaluates to true • IF/ELSE - Executes the ELSE portion if first condition is false, groups with the closest IF • ELSE IF - Navigates through until one statement evaluates to true Source: SF99 IF Statements

  11. Control Structure - Quiz! • If a cat weighs 15 pounds, how much food will they get based on the logic below?

  12. Control Structure - Loops • 3 different procedural loops • For Loops • Do - While Loops • While Loops Source: Salesforce, Loops

  13. For Loops • Different types: • Traditional • List or Set Iteration • SOQL Source: Salesforce, Loops

  14. Do-While Loops vs While Loops • Do-While: • Always executes the first statement at least once • Next continues to check the Boolean statement then executes Do again • While: • Only executes if the “while” condition is true Source: Salesforce, Loops

  15. For Loop - Order of Operations • Execute the init_stmt • Check the exit_condition. If true, continue on. • Execute the code_block • Execute the increment_statement • Return to step 2 Source: Salesforce, Loops

  16. Loops - Quiz! • What is the correct syntax to write a For Loop? Choose 2 answers • for (init_stmt; increment_stmt, exit_condition) { code_block} • for (variable : [soql_query]) {code_block} • for (variable: list_or_set) {code_block} • for (init_stmt, exit_condition) {code_block, increment_stmt}

  17. Loops - Quiz! • What will be the final value of x when the loop finishes? • 5 • 6 • 7 • 8

  18. Queries • SOQL - Used to construct queries that returns one or more fields from one or more objects • SOSL - Uses a text string to search across multiple objects Source: Salesforce SOQL and SOSL Queries

  19. Queries - Quiz! • A developer needs to query all dogs at the shelter who are less than 5 years old and haven’t been adopted yet. Which statement below holds the correct syntax? • SELECT Name, Age__c, Species__c FROM Pets__c WHERE IsAdopted__c = FALSE and Age__c < 5 and Species__c = ‘Dog’ • SELECT Name, Age__c, Species__c FROM Pets__c WHERE IsAdopted__c = “FALSE” and Age__c < 5 and Species__c = “Dog” • SELECT Name, Age, Species FROM Pets WHERE IsAdopted__c = FALSE and Age__c < 5 and Species__c = “Dog”

  20. Data Manipulation Language (DML) • Operations include: • Insert, Upsert, Update, Merge, Delete, Undelete • DML Statements • If an operation fails and exception is thrown and all changes rolled back • Database class methods • Allows for partial inserts if some records fail Source: Salesforce, Data Manipulation Language

  21. Apex - Putting it all together

  22. Triggers • Allow you to perform custom actions on Salesforce records when certain criteria are “triggered” • Contain references to Apex Classes • Two types of triggers: • BEFORE - insert/update/delete/merge/upsert/undelete • Use to modify fields before the record is saved to the database • AFTER - insert/update/delete/merge/upsert/undelete • Use to access system set values like Id or LastModifiedDate • Records that fire after triggers are read only Source: Salesforce Triggers

  23. Triggers • Trigger syntax: • trigger <TriggerName> on <ObjectName> (trigger_events){code_block}; Source: Salesforce Triggers

  24. Triggers • Context variables allow you to access run-time variables • Includes items such as: • isInsert, isUpdate, isDelete, isBefore, isAfter, new, old, size • Allows you to write triggers more efficiently, examples: • In a before update trigger, access both the previous and current value being updated using ‘new’ and ‘old’ • Combine all object operations into one object and call Apex Classes using isBefore, isAfter (best practice - called a Trigger Handler) Source: Salesforce Triggers

  25. Trigger Handler Example Source: Salesforce Trigger Framework and Apex Trigger Best Practices

  26. Triggers - Quiz! • A developer is required to create a trigger that prevents users from adding a duplicate product onto an Opportunity. What trigger event should they use? • before Merge • after Insert • after Update • before Insert

  27. Triggers - Quiz! • Will the below code succeed or throw an error?

  28. Governor Limits • Why are they necessary? • Multi-tenant environment • Types of limits per transaction (not inclusive): • 100 SOQL Queries issued • 50,000 records retrieved from SOQL Queries • 20 SOSL Queries issued • 150 DML Statements • 10,000 milliseconds CPU time

  29. How to Avoid Hitting Governor Limits • Never place queries inside loops • Never place DML statements inside loops • Only use 1 trigger per object and do not place logic directly inside the trigger • Watch out for code that triggers other processes • Bulkify your code - make sure it can handle more than one record at a time Inside Outside Source: Salesforce The 15 Apex Commandments

  30. Visualforce • A coding language used to alter the user interface of Salesforce

  31. Visualforce Controllers • Controller - A set of instructions on what happens when a user interacts with a page, types: • Standard Controller - same functionality and logic as standard Salesforce pages • Standard List Controller - enables you to create pages that display or act on a set of records • Custom Controller - Apex class that adds implements all of the page’s logic without leveraging the standard controller • Controller extension - Apex Class that extends the functionality of standard or customer controllers Source: Salesforce, What is Visualforce?

  32. Visualforce Controllers • Permissions: • Standard controllers execute in user mode • Custom controllers execute in system mode • Syntax: Source: Salesforce, What is Visualforce?

  33. Visualforce Methods • Methods are used in Visualforce to GET or SET values • Getter Methods - Included in every standard controller and can be defined in custom controllers • Always required to access values from a controller • Setter Methods - used to submit values from the Visualforce page back to the controller • Not always required to pass values if the Visualforce page is bound to an sObject • Syntax: {! expression_name} Source: Salesforce, What is Visualforce?

  34. Visualforce - Quiz! • A developer needs to create a Visualforce page that overrides the standard permissions. What controller do they need to accomplish this? • Standard List Controller • Custom Controller • Controller Extension • Setter Method

  35. Visualforce - Quiz! • What is the correct syntax for referencing a custom controller? • <apex:page standardController=”customControllerName” type=”custom”> • <apex:page controller=”customControllerName”> • <apex:page customController = “customControllerName”> • <apex pageBlock customController = “customControllerName”>

  36. Dynamic Apex • Describe how to programmatically access and utilize the object schema.

  37. Dynamic Apex • Allows you to access behind the scenes details (metadata) of Objects and Fields like: • Object/Field API and label names • Field description details • Security settings for the user who kicks off the code • Valid record types and picklist values • Max number of digits allowed in a field Source: Cap Tech Consulting, How to PASS Salesforce Platform Developer Exam

  38. Dynamic Apex • WHY? • Makes code more flexible • Ex: Can use the same piece of code on multiple objects • Not all developers have access to the target environment • Ex: Apps downloaded from the AppExchange must work for any environment • Allows you to access information not easy to query: • Ex: The permissions a user has on an object, return all fields on an object Source: Cap Tech Consulting, How to PASS Salesforce Platform Developer Exam

  39. Dynamic Apex • Schema Namespace - Contains a set of pre-defined classes and methods in Salesforce that allow you to access metadata • A namespace is identified using dot notation, example: Schema.Reports • Some examples: • DescribeFieldResult Class - Contains methods for describing sObject fields • DescribeSObjectResult Class - Contains methods for describing sObjects • DescribeTabResult Class - Contains tab metadata information in a standard or custom app Image Source: FocusOnForce.com - PD1 Study Guide

  40. Dynamic Apex • Example of commonly used methods in the Schema Namespace • From the DescribeFieldResult Class: • getDefaultValue(), getLabel(), getPicklistValues() • From the DescribeSObjectResult Class • isAccessible(), isCreatable(), isDeletable() • *These three methods describe the current user’s permissions on the current object Image Source: FocusOnForce.com - PD1 Study Guide

  41. Dynamic Apex - Homework! • Be familiar with the syntax of the different ways to describe metadata. Open up the below links and read the definitions • Schema Namespace - Get familiar with names of classes. • Get familiar with the names of the methods in these classes: • DescribeSObjectResult Class • DescribeFieldResult Class

  42. Dynamic Apex - Question Examples How can a developer check that a user can create records on the Visualforce page they are accessing? • Call the isCreatable() method of Schema.DescribeSObjectResult to verify • Call the isInsertable() method of Schema.DescribeFieldResult to verify • Call the isCreateable() method of Schema.DescribeSObject to verify • Call the isAccessible() method of Schema.DescribeSObjectResult to verify

  43. Dynamic Apex - Question Examples What three methods below can be accessed through the DescribeFieldResult class? • getName() • getLabel() • isCustom() • isStandard()

  44. Order of Operations • System validation rules • Before triggers • System validation rules + custom validation rules • Duplicate rules • Record saved (not committed) • After triggers • Assignment rules • Auto-response rules • Workflow rules • Before triggers/validation rules/after triggers executed from workflow updates • Processes • Escalation rules • Rollup summary fields and cross-object formula fields • Parent & grandparent records saved • Criteria-based sharing rules are evaluated • DML operations • Post-commit logic

  45. Topics not Covered: • Potential for recursion and cascading • Field updates that Re-Evaluate Workflow Rules • Avoid Recursive Triggers • Context Variable Considerations • Describe how to implement exception handling in Apex • Introduction to Exception Handling • Built in Exceptions and Common Methods • Create Custom Exceptions • Describe the programmatic techniques to prevent security vulnerabilities in Apex and Visualforce • Security Tips for Apex and Visualforce Development • Data Access Control • Trailhead: App Logic Vulnerability Prevention • Trailhead: Injection Vulnerability Prevention • Describe how Apex impacts the ability to make declarative changes • Notes on Changing Custom Field Types • Visual Development - When to Click Instead of Write Code Source: Focus on Force PD1 Study Guide

  46. Platform Developer I Certification Study Group Got questions?Unmute your line to speak or type into the chat box.

  47. Platform Developer I Certification Study Group *Schedule: June 28 – September 6, 2018 *Schedule was updated on 7/18/2018

More Related