Tag: Dreamforce

Dreamforce 2014 Notes: Write Apex Tests Using Best Practices

One of the hands on training sessions I attended was “Write Apex Tests Using Best Practices” which really proved to me that a lot of what I believed and was doing were right.

Without further ado, here’s my notes:


Goals for tests

  • Auomated methods that verify application integrity
  • Future Proof
  • Proactively Identify Problems before they enter production
  • Salesforce Runs all customer tests before updates
  • Postive tests & Negative tests
  • Classes that are demarcated by the @isTest annontation won’t count against Apex code limit
  • contain member methods that can only be contained & used in a test
  • tests always have a void return type & no params
  • tests are always static
  • single autonomous transaction
  • only heap space, governor, etc
  • tests should insert their own test data
  • tests should be able to handle uncaught exceptions, etc
  • tests should have assertions to determine validity

Tests Leave No Footprint

  • Apex tests will not commit changes. SOQL still finds records
  • will not performs callouts to external web services
  • will not send outbound email

 

Tests Expect to Work with Mock Data

  • static resources can be used to stage test data in a cache
  • SOSL searches will not find pre-existing records
  • SOQL queries will only find pre-existing records for the following objects:
    • User
    • Profile
    • Organization
    • RecordType
    • For all other objects, SOQL visibility may be overridden with @isTest(seeAllData=true)

Governors

  • verify code is bulk ready
  • pass up to 200 records

Verify End State

  • using assertions

Best Practices

Don’t Depend on Pre-Existing Data

  • Avoid SOQL to initalize SOQL using SeeAllData=true
    • less portable
    • inconsistent results
  • Utilize mock data
  • Call Test.loadData() in a test method to populate
  • Create reusable mock data factories
  • Triggers should never contain business logic, they should only contain calls to classes
  • Use a Naming Convention like NameOfClass_Test
  • Exclude mock data initialization and result verification actions from governor calculations
  • Create separate tests with narrow goals

Challenges

  • blue boxes: test logic
  • grey boxes: business logic

Testing Visualforce Controllers

  • Mimic VisualForce page interactions by explicity calling methods
    • Form fields, eg form.Name use getter/setters
  • Test controller extensions by mocking the controller that was extended

 

Test.startTest synchronously runs asynchronous Apex

Testing Callouts

  • developers need to implement mock calls and responses that do not access the web services
  • setMock() needs to be run to do the fake response and call out

Testing Record Access

  • use System.runAs() methods to verify test users can find records that were shared with apex
  • using System.runAs() is a best practice.

Looking Back at Dreamforce 2014

Welcome to DreamforceI was really blessed to be able to attend Dreamforce and learn even more about Salesforce.

While attending there, I attended a lot of the different keynotes and saw a lot of the new exciting features in action.

Dreamforce Sessions

At Dreamforce there was dozens of interesting sounding sessions. There were a few different ones that really stood out to me and offered interesting and new material to me. I believe that a lot of the sessions were recorded and able to viewed at a later date which is really exciting and available on youtube here.

One of my favourite sessions was Advanced Development using Apex Design Patterns by Robert Nunemaker. The vide is one if the hundreds uploaded by Salesforce to youtube here.

New Product Announcements

Before attending Dreamforce, I didn’t realize that Salesforce made a lot of its new product announcements there. Some of the new products they announced were: Lightning Components, Process Builder, Salesforce Wave,

Wave / Analytic Cloud

By Far, Wave was the most interesting announcement at Dreamforce 2014. It is a fairly dynamic business intelligence product that is optimized for use on mobile devices. What’s most awesome about Wave is that it will allow for on the spot and completely interactive exploration by business users rather than the static generated reports that have been prewritten.

Duplication Prevention

Through the use of fuzzy logic and other logic it will now be possible to stop duplication from occurring within Salesforce.

Sale Reach

Sales Reach units the power of Pardot, Communities and Sales Cloud into one system. Apparently, it will be able to do popup notifications on the Salesforce1 Application and assist with Leads/Prospect Tracking.

Lightning

Lightning is all about reducing development time and code. Lightning is basically a component framework and new set of tools that make building apps and making automation much faster.

Lightning Components allow developers to create reusable components for use in building apps. Lightning seems to be an event-driven architecture that makes use primarily of JavaScript and model-view controller architecture.

Process Builder allows business processes to be automated more easily and in a visual way.

Lightning Connect is the ability to connect to external data sources and with point and click be able to incorporate the data into Salesforce. The basic idea is that gone are the days of legacy systems and data silos, it would now be possible to use this data in Salesforce and with Wave.

Service Cloud

Smart Agent Console is designed to make it easier to provide good customer service to customers by making searching more intelligent, and where applicable making it possible to show sales data and billing data. It’s no secret that more competent agents allows companies to offer better service with less agents, reducing their service costs.

Community Cloud

Community Designer offers a few different themes that out of the box allow businesses to better connect to customers and reduce support costs. Community Designer allows new communities to be deployed by writing no-code and using point and click.

Topics allow users to access all of the relevant information in one place and even follow it to always stay up to date.

I’m so excited for Dreamforce 2015 and can’t wait to go.