1 / 93

Development Tools

Development Tools. Developer Console Force.com IDE (Eclipse Plugin) Mavens Mate (Sublime Plugin) Force CLI. Developer Console. Browser Based IDE Create Classes, Triggers, Pages Execute Apex Anonymously Execute SOQL Queries Run Unit Tests Review Debug Logs. Lab 3: Creating an Apex Class.

lindaleger
Télécharger la présentation

Development Tools

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. Development Tools • Developer Console • Force.com IDE (Eclipse Plugin) • Mavens Mate (Sublime Plugin) • Force CLI

  2. Developer Console • Browser Based IDE • Create Classes, Triggers, Pages • Execute Apex Anonymously • Execute SOQL Queries • Run Unit Tests • Review Debug Logs

  3. Lab 3: Creating an Apex Class • Create the EmailManager class • Send emails from the developer console

  4. Module 4:Accessing Data with SOQL and DML

  5. What’s SOQL? • Salesforce Object Query language • Similar to SQL • Streamlined syntax to traverse object relationships • Built into Apex

  6. SELECT Id, Name, Phone FROM Contact

  7. SELECT Id, Name, Phone FROM Contact WHERE Phone <> null

  8. SELECT Id, Name, Phone FROM Contact WHERE Phone <> null AND Name LIKE '%rose%'

  9. SELECT Id, Name, Phone FROM Contact WHERE Phone <> null AND Name LIKE '%rose%' ORDER BY Name

  10. SELECT Id, Name, Phone FROM Contact WHERE Phone <> null AND Name LIKE '%rose%' ORDER BY Name LIMIT 50

  11. Details to Master SELECT Id, Name, Phone, Account.Name FROM Contact WHERE Phone <> null AND Name LIKE '%rose%' ORDER BY Name LIMIT 50

  12. Details to Master SELECT Name, (SELECT FirstName, LastName, Phone FROM Contacts) FROM Account

  13. Executing SOQL in the Developer Console

  14. Inlining SOQL in Apex Integer i = [SELECT Count() FROM Session__c];

  15. Inlining SOQL in Apex String level = 'Advanced'; List<Session__c> sessions = [SELECT Name, Level__c FROM Session__c WHERE Level__c = :level];

  16. Inlining SOQL in Apex List<String> levels = new List<String>(); levels.add('Intermediate'); levels.add('Advanced'); List<Session__c> sessions = [SELECT Name, Level__c FROM Session__c WHERE Level__c IN :levels];

  17. Inlining SOQL in Apex for (Speaker__c s : [SELECT Email__c FROM Speaker__c]) { System.debug(s.email__c); }

  18. What’s DML? • Data Manipulation Language • Language used to create, update, delete records

  19. insert Session__c session = new Session__c(); session.name = 'Apex 101'; session.level__c = 'Beginner'; insert session;

  20. insert Session__c session = new Session__c( name = 'Apex 201', level__c = 'Intermediate' ); insert session;

  21. update String oldName = 'Apex 101'; String newName = 'Apex for Beginners'; Session__c session = [SELECT Id, Name FROM Session__c WHERE Name=:oldName]; session.name = newName; update session;

  22. delete String name = 'Testing 501'; Session__c session = [SELECT Name FROM Session__c WHERE Name=:name]; delete session;

  23. Lab 4: Accessing Data using SOQL and DML • Execute SOQL statements in the Query Editor • Execute DML statements in the Anonymous Window

  24. Module 5:Writing Triggers

  25. What’s a Trigger? • Apex code executed on database events • Before or after: • Insert • Update • Delete • Undelete

  26. Before or After? • Before • Update or validate values before they are saved to the database • Example: Prevent double-booking of a speaker • After • Access values set by the database (Id, lastUpdated, …) • Example: Send speaker confirmation email

  27. Bulk Mode • Triggers work on lists of records, not single records • This is to support bulk operations • Data Import, Bulk API, etc. • Context variables provide access to old and new values: • Trigger.old and Trigger.new (List) • Trigger.oldMap and Trigger.newMap (Map)

  28. Example 1 trigger WelcomeKit on Account (after insert) { List<Case> cases = new List<Case>(); for (Account account : Trigger.new) { Case case = new Case(); case.Subject = 'Mail Welcome Kit'; case.Account.Id = account.Id; cases.add(case); } insert cases; }

  29. Example 2 trigger on Account (before update) { for (Account acc: Trigger.New) { // Compare new value with old value if (acc.Rating != Trigger.oldMap.get(acc.Id).Rating) { // Your Logic } } }

  30. Workflow vs Trigger

  31. Lab 5: Writing Triggers • Write the SendConfirmationEmail trigger • Write the RejectDoubleBooking trigger

  32. Module 6:Writing Visualforce Pages

  33. What's a Visualforce Page? • HTML page with tags executed at the server-side to generate dynamic content • Similar to JSP and ASP • Can leverage JavaScript and CSS libraries • The View in MVC architecture

  34. Model-View-Controller • Separation of concerns • No data access code in view • No view code in controller • Benefits • Minimize impact of changes • More reusable components View UI code Controller View-Model interactions Model Data + Rules

  35. Model-View-Controller in Salesforce • View • Standard Pages • Visualforce Pages • External apps • Controller • Standard Controllers • Controller Extensions • Custom Controllers • Model • Objects • Triggers (Apex) • Classes (Apex)

  36. Component Library • Presentation tags • <apex:pageBlock title="My Account Contacts"> • Fine grained data tags • <apex:outputField value="{!contact.firstname}"> • <apex:inputField value="{!contact.firstname}"> • Coarse grained data tags • <apex:detail> • <apex:pageBlockTable> • Action tags • <apex:commandButton action="{!save}" >

  37. Expression Language • Anything inside of {! }is evaluated as an expression • Same expression language as Formulas • $ provides access to global variables (User, RemoteAction, Resource, …) • {! $User.FirstName } {! $User.LastName }

  38. Example 1 <apex:page> <h1>Hello, {!$User.FirstName}</h1> </apex:page>

  39. Standard Controller • A standard controller is available for all objects • You don't have to write it! • Provides standard CRUD operations • Create, Update, Delete, Field Access, etc. • Can be extended with more capabilities (next module) • Uses id query string parameter in URL to access object

  40. Example 2 Standard controller object <apex:pagestandardController="Contact"> <apex:form> <apex:inputField value="{!contact.firstname}"/> <apex:inputField value="{!contact.lastname}"/> <apex:commandButton action="{!save}" value="Save"/> </apex:form> </apex:page> Function in standard controller

  41. Where can I use Visualforce? Email Templates Embedded in Page Layouts Generate PDFs Custom Tabs Page Overrides Mobile Interfaces

  42. Lab 6: Writing Visualforce Pages • Write the SpeakerForm Visualforce page • Set it as default for creating and editing speakers

  43. Module 7:Writing Controller Extensions and Custom Controllers

  44. What's a Controller Extension? • Custom class written in Apex • Works on the same object as the standard controller • Can override standard controller behavior • Can add new capabilities

  45. Defining a Controller Extension Provides basic CRUD <apex:page standardController="Speaker__c" extensions="SpeakerCtrlExt"> Overrides standard actions and/or provide additional capabilities

  46. Anatomy of a Controller Extension public class SpeakerCtrlExt { private final Speaker__c speaker; private ApexPages.StandardControllerstdController; public SpeakerCtrlExt (ApexPages.StandardController ctrl) { this.stdController = ctrl; this.speaker = (Speaker__c)ctrl.getRecord(); } // method overrides // custom methods }

  47. What's a Custom Controller? • Custom class written in Apex • Doesn't work on a specific object • Provides custom data • Provides custom behaviors

  48. Defining a Custom Controller <apex:page controller="FlickrController">

  49. Custom Controller Example public with sharing class FlickrController { public FlickrListgetPictures() { HttpRequestreq = new HttpRequest(); req.setMethod('GET'); req.setEndpoint('http://api.flickr.com/services/feeds/'); HTTP http = new HTTP(); HTTPResponse res = http.send(req); return (FlickrList) JSON.deserialize(res.getBody(), FlickrList.class); } }

  50. Lab 7: Writing a Controller Extension • Write a Controller Extension that supports Picture Upload

More Related