Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DF18: Everything that's Awesome with Apex

DF18: Everything that's Awesome with Apex

Chris Peterson

September 26, 2018
Tweet

More Decks by Chris Peterson

Other Decks in Programming

Transcript

  1. Forward-Looking Statements Statement under the Private Securities Litigation Reform Act

    of 1995 This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  2. Switch Statement 17,110 Points • Switch on most primitive types

    • Switch on a generic SObject instance • Use multiple literals for the same ‘when’ condition COUNT() Queries Without Worrying About Limits 7,010 Points • Count queries only consume one query row for limit purposes RecordTypeInfo.getDeveloperName() 4,990 Points • Get Record Type API names without a SOQL query Apex Code Size Limit Increase 360 Points • Organizations default to 6MB of Apex non-test code storage, up from 3MB Instantiate Custom Metadata Types in Apex • Construct and edit custom metadata fields in memory without DB update 30,000 IdeaExchange Points Quality of Life
  3. Compile On Deploy • Apex will automatically recompile as part

    of metadata deployments to production organizations • Avoids performance overhead on first use from "cold cache" • Opt-in for sandbox and developer edition orgs Skip Test Coverage Calculation • Optionally bypass collecting fine-grained test coverage data for faster test execution • One less barrier to test-driven-development patterns Deployment Cache • Tests make better use of cache • Faster deployment times Always looking out for improvements Performance
  4. Detailed, actionable error reporting for Batch Apex Introducing: Batch Apex

    Error Events Batch Error Events include: • AsyncApexJobId • All recordIds in scope for the job chunk • Exception type • Exception message • Stack trace • RequestId (correlate with Event Monitoring data) Dramatically improved visibility into issues • Know which records were committed and which to retry Programmatically react to errors in real-time • Retry failed jobs - enqueue jobs from your event handler (if you want) Log with all the verbosity you could ever want • Full context available in events, including impacted records • For Iterator-based jobs, the Object.toString() value is used Opt-in, doesn't count for limits • To opt-in, implement Database.RaisesPlatformEvents • Standard platform event type doesn't count aginst org limits
  5. Where we are investing • Security • Quality of life

    (true to the core) • Language server • Asynchronous Apex • Platform Cache
  6. Coming soon (Spring ‘19, Summer '19) Better visibility of Org

    Limits • Daily Async Apex Executions • Daily API Requests • Data & File Storage • … everything else sfdx force:limits:api:display / Rest API shows you Platform Cache available in scratch orgs • Platform cache capacity as a scratch org feature • [Optional] Automatically shrink deployed partitions to 1MB • Reduced minimum partition size to allow testing multiple partitions Refactoring support in Apex Language Server (Visual Studio Code) • Rename Symbol CRUD/FLS checks
  7. Coming less soon Apex Language Server: expanded refactoring • Implement

    missing interface methods • Extract variable Platform Cache: Apex Metadata API Support • Allow ISV applications to automatically provision cache in post-install • Programatically re-configure cache partition sizing as needed Anonymous Inner Classes • Long-requested feature to cut down on boilerplate code Async enhancements • Continued batch robustness and visibility enhancements • Fast queueable • Consolidate futures and queueable
  8. Why? • A secure by default flexible sharing mode •

    Make developer intent explicit • Breeze through AppExchange Security Review What? • Sharing mode is inherited from calling class • If entry point, then sharing mode will be with sharing When? • Service layer classes, even if global • General use utility classes • Keep your controller classes with sharing New sharing mode in Winter '19 Inherited Sharing
  9. Inherited sharing in practice Apex Entry Point: <apex:page controller= "SampleController"

    …. public inherited sharing class SampleController Effective Mode: WITH SHARING global inherited sharing ServiceLayerClass Effective Mode is unchanged, nothing has explicitly elevated permissions Apex Entry Point: <aura:component controller= "OtherControllerClass" …. public without sharing class OtherController global inherited sharing ServiceLayerClass Effective Mode: WITHOUT SHARING
  10. How's it different? Apex Entry Point: <aura:component controller= "OtherControllerClass" ….

    public class OtherController global ServiceLayerClass Effective Mode is unchanged, still WITHOUT SHARING Apex Entry Point: <apex:page controller= "SampleControllerClass" …. public class SampleController Effective Mode: WITHOUT SHARING global inherited sharing ServiceLayerClass Effective Mode is unchanged, still WITHOUT SHARING Avoid: mixing no sharing declaration and inherited sharing Effective Mode: WITHOUT SHARING
  11. Object and Field level security Roll-your-own security means 1. Lots

    of boilerplate code 2. Security gaps (inadvertently or intentionally ignored) 3. Performance overhead 4. Difficult to audit: ◦ requires advanced static analysis tools ◦ long security review cycles ◦ higher risk of failing security review (see #2) FLS/CRUD
  12. FLS/CRUD Soon (Spring ‘19) WITH SECURITY_ENFORCED • straightforward • blunt

    tool Later SObjectAccessDecision Security.stripInaccessible(AccessType accessCheckType, List<SObject> target) //Not finalized syntax • gives dev more control • requires more skill Access check enforcement roadmap  
  13. Apex in Trailhead Advanced Beginner Intermediate Apex Enterprise Patterns: Domain

    & Selector Layers Apex Enterprise Patterns: Service Layer Apex Metadata API Apex Specialist Advanced Apex Specialist Apex & .NET Asynchronous Apex Asynchronous Integration Services Apex Quick Start Apex Basics & Database Apex Triggers Apex Testing Apex Coding for Admins
  14. Check out these recent blog posts Salesforce developers blog (Emily

    Kapner): Keep Your Org in Tip-Top Shape with Deployment Best Practices Andy (Fawcett) in the cloud: Managing Dependency Injection within Salesforce Salesforce developers blog (Peter Chittum): Rethink Trigger Logic with Apex Switch
  15. Q&A