How do I change who gets Apex Error Emails?

I got this question a few times at Dreamforce this year so I thought I would quickly cover it. If you don't want all the System Administrators to see this or would just prefer a specific user(s) get the details there is now an easy way to do this.

Go to Setup and run a quick search for "Apex Exception Email"

Quick Search for "Apex Exception Email"

In the expanded section click on "Apex Exception Email"

From here you can choose either a Salesforce user or users and/or to a non-Salesforce user email.



Simplified API limits with Winter '17

One of the headaches for ISVs and even internal developers was efficiently keeping tracking of the current API limits on the ORG. About a year ago Salesforce started to return these limits as part of the SOAP headers so that you could get a real-time count. The problem was that you had to burn API to get the latest count.

I'm excited to see in the pre-release notes for Winter '17 that Salesforce has simplified this. It used to be that for Enterprise Edition, Unlimited Edition, Performance Edition, and Professional Edition with API access enabled, the old calculation was based on your number of licenses and the license types, with a guaranteed minimum of 15,000 calls per 24-hour period. Salesforce has now changed this and set the minimum to 15,000 calls per 24-hour period. 

To me this is a huge help - especially for smaller orgs that only have under 3-10 licenses. I'm very excited to get this rolled out and think it's a step in the right direction. 




Salesforce Record Size

As a general rule of thumb - regardless of whether you have 10 fields on an object or 80, Salesforce allocates and estimates 2k for more records. This is all about both performance, governor limits and your storage limits. To learn more check out KB 000193871

Below is a breakdown


Leads -- 2KB
Contacts -- 2KB
Accounts -- 2KB
Person Accounts - 4KB
Opportunities -- 2KB
Tasks -- 2KB
Forecasts -- 2KB
Events -- 2KB
Cases -- 2KB
Case Team Member – 2KB
Solutions -- 2KB
Notes -- 2KB
Custom Reports -- 2KB
Tags: unique tags – 2KB
Campaigns - 8KB
Campaign Members – 1KB
Contracts – 2KB
Google Docs – 2KB
Quotes – 2KB
Custom Objects – 2KB
Quote Template Rich Text Data - 2KB
Articles - 4KB


Person Accounts - You need to keep in mind that with Person Accounts there is an account record and a hidden Contact record associated with it and that is why it is double that of a lead or an account.

Email Messages - This is primarily up to the content size and is a 1 to 1 ratio. 100kb of content takes up 100kb of data storage space.

Note when testing - I really encourage my friends (and anyone who will listen) to take the time and add a few hundred fields to leads, contacts and accounts and make sure you test your code against it. Obviously the more fields you bring back in a SOQL query the more memory and CPU time you are going to use but the point is you want to be prepared for that down the road. 




Local Timezones Now in Debug Logs

One of the things that I've been advocating for the last few years is to show my actual time zone in the debug logs. When you're trying to solve a problem and really honed in it, it is a pain to constantly translate back and forth to GMT. I am super excited and have been the heck out of the new enhancement so my hat goes off to the Salesforce dev team. LOVE IT. If you look at page 345 of the Summer 16' Release notes PDF you'll the same image below. 


Mapping Fields for Lead Converstion

A lot of valuable information can be captured on a lead and in most cases I see it is just lost. People just simply forget to go map the fields over to Contact/Account and finding the place to do this is not super obvious either. Using the latest release Summer 16' we'll show you below a quick reminder on how to map your lead fields in Salesforce to the proper fields on the Contact and Account objects so that the data is not lost.

Step 1)

Go to Setup-->Customize-->Lead-->Fields

Salesforce Lead Conversion Field Mapping Step 1 

Step 2)

Click on the Lead Field Mappping Button in the section between the standard Salesforce Lead fields and the Custom Lead Fields

Salesforce Convert Map Lead Fields


 Step 3)

Map the various Salesforce Lead fields to the fields on the Salesforce Contact and Account objects. During the SalesforceLead converstion these values will then transfer to those fields on the object of choice.

Salesforce lead to contact and account field mappingUpon Saving, you'll get a confirmation and all future Salesforce lead conversations should follow this pattern.


10 Principles of Apex Testing (by Salesforce)

I actually just watched this the other day for the first time when thinking of topics for the Dallas Salesforce Developers User Group or as we just say #sfdug.

I highly recommend this one to those getting started or just trying to brush up on skills.

Like it or not, testing your Apex code is a requirement for deployment. Often it seems developers are frustrated with testing because it seems like a platform imposed chore, rather than a useful software development tool. Apex developers can harness testing as a way of improving software quality.

Find it here:

You'll find both the webinar format and the slides.



SOQL Query Optimization - Causes/fixes of Non-Selective Queries

As we all begin to work with larger and larger datasets, we're bound to run into issues with non-seletive SOQL queries. Let's start out with a definition so we're all on a same page.

Non-selective queries are SOQL queries (typically against) tables with more than 100k rows that bring back 100k rows. i.e. you have not specified speficially what you are looking for so a full table scan is happening and if it were to proceed too long would cause locking.

Sample error: System.QueryException: Non-selective query against large object type (more than 100000 rows).


This usually happens in the context of a trigger because Salesforce is careful to make sure that transactions and therefore locks do not last very long. Note very specifically that it occurs in a trigger. Many times if you run that same query from an Apex Class called outside the context of a trigger or through Execute Anonymous you will not see the error. - Terry Luschen


At the heart of every SOQL query is the underlying database. Every relational database managment system (RDMS) has what is a called a query optimizer at its core. Before a query hits the database it parses the query, looks at what you are asking for and determines the fastest way to get it.


Query optimization is a function of many relational database management systems. The query optimizer attempts to determine the most efficient way to execute a given query by considering the possible query plans. - Wikipedia


So what are some of the root causes of a non-selective SOQL query?

  • Too many records - again, when you get a table above 100k rows and start asking for records that meet the condition of all 100k rows you're going to hit this issue. For example, let's say all your Contacts were imported on Aug 1, 2011 when you migrated to Salesforce. If you run a query that says: 
         SELECT id FROM Contact WHERE CreatedDate  > 2010-01-01T00:00:00Z

  • Using the good ol' Wildcard - a LIKE condition that has a leading "%" WILL NOT USE an index
         SELECT id FROM Account WHERE Name LIKE ‘%Acme%’ //this would be better suited for a SOSL query

         WHen you build a report or use a list view where you add a Contains clause that is the same

         as doing what we have adove - it essentially translates to %Value%.

  • Using NOT and != in your query - When you filter on these two inequality filters the query optimizer cannot take advantage of the index to make the query faster. By doing the opposite and filters on "=" or using an IN ('a','b','c').
  • Complex Join statements - when you start to build in complex AND/OR logic into the queries and adding sub-queires - this forces the query optimizer to produce and optimized query for the join. In reality it may be a lot more efficient to break these into multiple queries. I have found this to be particularly true when I see a lot of OR logic in the queries I look at.

If Salesforce is going to use an index when an OR condition is involved - ALL the fields you have listed in the OR condition must be indexed fields.


Salesforce Spring '16 - System.Test setCreatedDate

Really excited to see the new method added to System.Test that allows you to set the created date/time of a record. This is super helpful when inserting test data and you want some of it to appear to be older.

//Sets CreatedDate for a test-context sObject.

setCreatedDate(recordId, createdDatetime)


Debugging Apex Made Easier in Winter '16

With the release of Winter '16, Salesforce has taken a big step forward in making it easier to debug Apex code. One of the hard things we have all had to deal with is that debugging Apex is very much a "print line" exercise up to now. 

The Apex Debugger in Eclipse is now being released for general availability. It behaves very similar to debuggers from other languages for those of us who started out in Java, C++, C# etc. I've used it in my sandbox and I am able to set a breakpoint, start a debugging session and determine root causes.

Features & Uses


  • Set breakpoints in Apex classes and triggers
  • View variables, including sObject types, collections, and Apex System types.
  • View the call stack, including triggers activated by Apex Data Manipulation Language (DML), method-to-method calls, and variables
  • Interact with global classes, exceptions, and triggers from your installed managed packages. When you inspect objects that have managed types that aren’t visible to you, only global variables are displayed in the variable inspection pane.
  • Complete standard debugging actions, including step into, over, and out, and run to breakpoint
  • Output your results to the Console window