Follow up to Spring ’16 Feature – Run Script for Sandbox

A follow-up post to and the Spring ’16 release feature Run Script after Sandbox Create or Refresh.

This was the original use case I wanted to cover (pending a support case and bug issues), functionality to auto refresh a custom setting with environment information.

In a production environment I have a custom setting (hierarchy type) that contains the environment Id, Name, Type, and URL.


…and it has the following data:


When a sandbox is created or refreshed from the production environment it pulls the custom setting data with it, but in this use case, it no longer relevant for the environment. I’m coming from the production environment, but I now want the relevant Sandbox environment information.  Now with an apex class that implements SandboxPostCopy interface, I can have this data auto populated when the sandbox is created or refreshed.  Here’s what the apex class looks like:

global class sandboxCreateRefreshScript implements SandboxPostCopy

global void runApexClass(SandboxContext context)

Environment_Settings__c es = Environment_Settings__c.getorgdefaults();

es.Environment_Type__c = 'Sandbox';
es.Environment_URL__c = URL.getSalesforceBaseUrl().toexternalform();
es.Environment_Id__c = String.valueof(context.sandboxId());
es.Environment_Name__c = context.sandboxName();
update es;


and test class…..

private class sandboxCreateRefreshScriptTest
@testSetup static void testData()
Environment_Settings__c es = new Environment_Settings__c();
es.Name = 'test';
insert es;
@isTest static void testSandboxPostCopyScript()

sandboxCreateRefreshScript sandboxScriptclass = new sandboxCreateRefreshScript();
Test.testSandboxPostCopyScript(sandboxScriptclass, UserInfo.getOrganizationId(), UserInfo.getOrganizationId(), 'sandboxName');

Environment_Settings__c es2 = Environment_Settings__c.getorgdefaults();
system.assertNotEquals(null, es2.Environment_Id__c);

On the sandbox wizard you’ll see we have the option of specifying the apex class to run that has the SandboxPostCopy interface.  Simply input the class name and submit.



After the sandbox refreshes, we now have our data auto populated:

Screen Shot 2016-04-25 at 12.05.34 PM



Spring ’16 Feature – Run Scripts for Sandbox

A neat feature in the Salesforce Spring ’16 release is the Run Script after Sandbox Create or Refresh.  This could be helpful for environments that need some dummy data or static data populated in developer, partial, or full sandbox.

Let’s take the following very simple use case.  Another update with Spring’16 is the increase number of developer sandboxes.  Now we have the ability to create 25 at a time.  Because developer sandboxes do not copy record data with it, if you need let’s say Accounts then its up to you to create them each time you spin up a sandbox.  With this new sandbox script feature we could automate creating test Accounts.

For this example, I’m going to create 10 Accounts when a sandbox is created or refreshed.  To do this I’ll need to build an apex class that implements the SandboxPostCopy interface.  Inside I’ll loop through and build 10 accounts with some sample data.

global class sandboxRefreshScript implements SandboxPostCopy
global void runApexClass(SandboxContext context)

List<Account> accounts = new List<Account>();
for(Integer x = 1; x < 11; x++)
Account a = new Account();
a.Name = 'Test Account ' + x;
a.Type = 'Client';
a.BillingState = 'NC';
a.BillingCity = 'Greensboro';


insert accounts;

…and of course we need a test class with it.  Under the Test class we now have the method testSandboxPostCopyScript in which we pass the SandboxPostCopy class,  Id’s for sandbox Id and org Id, along with a sandbox name.

private class sandboxRefreshScriptTest
@isTest static void testScriptRun()
system.assertequals(0, [Select count() from Account]);

sandboxRefreshScript sandboxScriptclass = new sandboxRefreshScript();
Test.testSandboxPostCopyScript(sandboxScriptclass, UserInfo.getOrganizationId(), UserInfo.getOrganizationId(), 'sandboxName');

system.assertequals(10, [Select count() from Account]);



When we create or refresh a sandbox we now have the following option to attach a sandbox script.


After my sandbox has been created, I can see I now have 10 accounts!

Screen Shot 2016-04-07 at 8.29.18 AM


Two additional notes:

1.) When you sandbox is activated (manual or auto) you should receive a second email saying that your script has run.

Screen Shot 2016-04-07 at 8.32.13 AM

2.) For record insertion, keep in mind the owner will not be the person that started the sandbox create/refresh.  The owner will be “Automated Process”.




Just Trailed….Migrating to Lightning Experience

Hope you got to experience the Salesforce live event for the Lightning Experience announcement.  We actually put on a viewing party and there was a great turn out, plenty of enthusiasm to go around.  Just my opinion, but I’m really excited about the new UI and all the goodies it brings with it.  If you’re wondering how to start getting your hands dirty, there’s two ways.  The first is to sign up for Winter 16 Pre-release Org.  The second is to dive into the new Trailhead trails that walk you through a few things on the new lightning experience.

To start I went through the Migrating to Lightning Experience trail, you’re going to hear about a few things:

You’re going to see “experiences” (aka the UI) divided into two buckets.  One being the new Lightning UI and the existing, now termed Salesforce Classic.  Other than the look and feel, there are some differences.  Currently certain objects won’t work in the new UI, but you’ll gain some new features like slick looking layouts, a more intelligent homepage, and a component building approach, so pay attention to the differences.  Based on how your Org is setup and your use cases this will play a part into how and when you migrate.

Did I mention there are going to be differences?  This trail was awesome in laying them out, going through the homepage, accounts and contacts, etc and show you the pros and cons to each.  There is even an assessment checklist to get you starting in determining what all you have in your environment.  Some big changes you might run into:

Opportunity Pipeline Board: all new in lightning experience

Reports/Dashboards and List views: so slick in the new UI

(Insert your object) Teams, Quotes, Forecasting, Campaigns: not in the new UI yet

Homepage improvements: such a good pull to get you in the new UI

URL Hack Buttons: say goodbye


Setting it up?  It’s actually pretty straight forward as the trail will lead you down.  There are some additional features to consider turning on before you flip the final switch (Sales Path, Enhanced Notes, Shared Activities, etc) but the setup area will give you a heads up on the Lightning Setup Page.  Once on you’ll also have control over who gets access through Permissions Sets.   Between that control and flipping between the new UI’s (within the Setup dropdown), Salesforce really did provide an easy way to manage this dipping of the toes in the water.


Already in?  The new UI you’ll notice right off the bat.  One thing I didn’t initially expect was the new Setup area.  This trail will go through what you’ll see and need to know.  How Setup tree has been reset from Administer, Build, Deploy, and Checkout to three sections: Administration, Platform Tools, and Settings…the new Create Menu, and how all objects are listed together just to name a few.

Another thing you’ll notice…ever get confused about if its an App or just a Tab?  Where do I go to see my Apps anyways?  The new UI gives a more focused approached to the Apps in your environment and with the App Launcher you can see all of them together and jump around if necessary.

How do I manage (Administer) two UI’s?  In short you can still use your layouts but compact layouts are your new best friend, but you’ll be surprised how many existing things are supported in the layouts in the new UI.  This trail does a great job going over those options and what to be aware of.


The last thing you’ll run into on this Trail is a call to action, how to roll this out.

Learn and Educate- Go through the trails, sign up for the pre-release or turn it on in you dev/sandbox org.   Work with your key stakeholders and super users.

Plan – Use the Gap Analysis and Assessment tips provided in this Trail.

Launch and Iterate – Put it out there for your super users, work with them, make it better…..wash, rinse, repeat!





3 Reasons Dreamforce Is All Its Cracked Up To Be

Reason 1 - The divide between Admins and Developers is closer than ever.

The functionality that Salesforce provides proves this time and again not only with moving capabilities to clicks, but the ability for clicks and code to work closer together.  Take flow and process builder for example.  We have platform tools that can call out to code and and work together, and vice versa.  This can also be seen with Zone placement at Dreamforce.  Both Admin and Developer Zones are in Moscone West.  So are the keynotes!  There is no excuse to check out both!

Reason 2 - Salesforce likes to shake things up.

Whether its product releases, announcements, the Gala, sessions and keynotes, Dreamforce is place for innovators and disruptors.  Every Dreamforce conference is unique and comes with a different vibe.  Attend any keynote, look at any roadmap, talk to anyone at any zone, Salesforce is looking to the future in how it builds cloud functionality.

Reason 3 – If walk away empty handed, its your own fault.

The anxiety with every Dreamforce isn’t if you walk away with something, its how do you craft your agenda to maximize the most potential. What is “something” you ask?  It could be knowledge from the 1500 sessions.  It could be inspiration from the keynotes.  It could be strategic plans from the roadmaps.  It could be partnerships from other clients and vendors.  It could be a broader network through the community on hand.  With so much to be involved in, it’s impossible to walk away from Dreamforce empty handed.


Getting Ready for Dreamforce!

Ok I’ll admit it, when I saw there is a trailhead badge for Getting Ready for Dreamforce, I really didn’t give it much credit.   Sure I thought, it will have some fluff information in there and I thought it would be more marketing than meat.

You hear about the 1500 sessions, keynotes, the expo and gala, same old same old…..and then I did the badge, and remembered I’ve been fortunate to attend more then a few Dreamforce’s.  I also remember my first time attending the conference……I was overwhelmed and exhausted trying to keep up.  I wish I had something like the Getting Ready for Dreamforce badge back then.

I just got the badge….and it was a great set of information, quick and precise, and some pro-tips along the way.

Get your Dreamforce badge?….get it the day before the conference, the day of will have long lines.  Prepare the day before, the next few days will be a sprint and a marathon all in one.

Develop a Dreamforce strategy?  Soooooo true, after my first Dreamforce experience I learned to come to the conference with a plan based on short and long terms goals.  Plan some downtime, some free style time, slice and dice your session searching by roles, products, and themes.  All great information to keep in mind.

Admin Zone vs Dev Zone? Both….just because you are one or the other doesn’t mean you have to stay in the respected Zone, you need to check out both.  Challenge yourself in both areas to learn and connect.

It’s also refreshing to see Salesforce up front on a couple things:

  1. When agenda builder goes live, act quick.  By now the agenda builder has been live for a while, but its refreshing to see Salesforce remind us about it, instead of the pro’s knowing it by experience and the newcomers being caught off guard.
  2. Success Community involvement, get in there and stay connected.  Through the Success Community, all your connections you make at Dreamforce will live on year round!

For some additional Dreamforce hacks, check out my post from last year’s event: my top 6 dreamforce hacks.

Oh and also….I’m #DF15 ready! :)

Are you? #DF15 Ready

Screen Shot 2015-08-12 at 8.42.58 PM



Apex testing with @testSetup

A couple releases back Salesforce provided a new annotation @testSetup for your fun loving Apex Test classes.  Over the past months I’ve used this more and more for my unit testing, and now its my go to on initial test class creation.  Along the way I had questions and thoughts about this new functionality that I want to share:

Should this replace a test data utility/factory?

In my opinion no, I still use a “TestDataUtility” that has methods to quickly give me 10 accounts, 250 leads, etc.  What I actually do is call that utility inside my @testsetup method, make any additional modifications, and then perform DML

What are the benefits of @testSetup?

So one thing you would assume is the data is automatically available throughout the test class, but that’s not the case.  If you insert records in a @testSetup method, you can’t reference them throughout the class in other unit test methods, you have to query for them.  So you may ask….what’s the point?  I can think of a couple:

  1. You still consolidate your test data in one method for the entire class.  It gives you a great baseline for your unit tests.
  2. From my brief performance review, it actually ran quicker to query for the data each time than to keep performing DML in each unit test method.  In some cases it was 20-35% faster on runtime.  Granted there could be environment factors, but still a performance increase.
  3. Edits and modifications are quicker.  If my baseline is off because of changed or new requirements and the edits don’t belong in the test data utility, I still only edit in once place, the @testSetup method.

How difficult is it to use this new annotation?

I started on the fence about using this, but quickly found my rhythm with using @tesSetup.  It became really handy with my test classes that blossomed into 4-5 unit test methods.  Now by default its the first thing I do in a test class.



Summer of Trailhead Leaderboard

UPDATE: (07/31/15) If you want to do an auto fresh on the page, check out some browser extensions that can handle that, for example for chrome: Easy Auto Refresh


The Charlotte user groups just completed a highly successful (yea there was ice cream and prizes!) Salesforce Summer of Trailhead event.  In total just over a 25,000 points were won in a little over 2 hours, with our winner gaining 8k points alone!

A neat feature we had at the event was a Trailhead Leaderboard showing the “Trailblazers”, points they had, and a countdown to when the contest ended.

trailhead leaderboard


The page itself wasn’t that crazy to put together in a dev org using Contacts, custom fields, a Visualforce page with Apex Controller, and a javascript file to control the countdown.  Add in some custom links and a custom setting for managing some of the page pieces and its a quick little solution.

Want to check it out and use it?  Please do!  I’ve done two things, one is packaged all this up together so you can install in a Salesforce org (developer environment suggested) and I’ve also posted the code to github which  gives you a quick rundown and gives you the link to install the package.

Any questions, let me know!  Blaze a trail!



Salesforce Spring ’15 – Platform and Developer Features

A great way to kick off the new year is to dive into the Salesforce Spring ’15 release notes.  In this post I’ll dive into the feature that caught my eye for the platform and developer features.  As always this isn’t an all inclusive post, make sure to catch the release notes to see what catches your interest. Customization

Advanced Setup Search – In my Winter ’15 post I went over this new feature that went open Beta.  In this release more items have been added, to include assignment rules, custom buttons, and custom links.

Standard Account Address / Google Map – If enabled (Customize –> Map and Locations –> Settings –> Enable Map and Location Services) a Google map will now appear under the standard account address.  To show the map you need to enter the address, city and one of the following: state, postal code, country.  Otherwise the map will not show.


Geolocation Fields – These fields are now generally available, previously only as a beta.  Along with the ability to reference in SOSL, SOQL, visual workflow, workflow rules, and approval processes.

Indexed Column – Now when you view your list of fields in Setup for an object there will be a column for which fields are indexed.  This may be a small change, but a huge asset to understand which fields are currently indexed by Salesforce.


Field Audit Trail – This feature is now GA, to let you retain field history for up to 10 years.  The metadata API has to be used to set the retention settings and then you can use other APIs (Rest, SOAP, Tooling) to work with the archived data.

Lightning Process Builder – Big news is this is now GA, which I’m sure is a welcomed and quick fast track from just going to beta last release.  New features in this release:

  • Call Apex action, to point to and process apex method
  • Versioning of Processes
  • Process record multiple times (up to 5) in same transaction.
  • Condition Logic now available, ex: 1 AND (2 OR 3).
  • Builder updates: Sort processes, expand/collapse actions, node highlighting when working on, Deprecated some status (now only Active and Inactive is available), multi-picklist values now available.
  • Limit of 10 immediate and 10 scheduled actions has been removed.

Flow – A lot of updates on flow this time around:

  • You can now pause flows to accommodate for interruptions, and pick them back up when ready.  Administrators can select which users can pause flows, provide a button to do so, and provide messaging to confirm flow is paused.
  • Condition logic is now available, 1 AND (2 OR 3).
  • Dynamic Labeling is now available for each flow in process.
  • Trigger ready flows renamed to Autolaunced flows.
  • Reference information and Id from actions that occured (chatter post id, approval process submitted info)
  • Event output information can now be available that the flow waited for.  When the “Wait” element concludes you can capture the status and date/time.

Monitor Login Activity – is now GA, you can use event monitoring to to see when and how often your users are logging in. This data is available for 24 hours and through the EventLogFile sobject.

Manager Groups – are now available for all orgs.  This allows the ability to share records and give access through sharing rules even when “Access Using Hierarchies” is disabled for an object.


  • Publisher Actions are now termed Quick Actions
  • Record Actions are now termed Productivity Actions
  • You can now create/assign or edit Accounts, Opportunities, and Custom Object records owned by an Inactive user.  Previously only available to Administrators.
  • Better formula monitoring for compound fields (can now use isnull, isblank, ischanged) Development

Quick Deploy – I mentioned this in the Winter ’15 release, and I’m excited to read its GA with Spring ’15.  Deploying to a production org with a multitude of test classes can be an exercise in patience.  With this new feature, as long as the validation run (and test classes) has executed you then have 4 days (96 hours) to “quick deploy” your components, meaning the target environment test classes don’t have to run again.

Visualforce Map Component – Along the mapping theme in this release you now have a VF tag to create a map component inside a VF page. <apex:map /> to create the map canvas and <apex:mapMarker /> to create the marker for the map.


Apex Flex Queue – is now GA, you can submit up to 100 batch jobs that will be held in holding status.  When resources are available a job is retrieved an moved from the Apex flex queue into the batch job queue.  The ability to process 5 queued or active jobs hasn’t changed, but this provides a much more flexible (see what I did there?) mechanism and pipeline for these jobs.  Also you can modify the order of jobs held in the Apex flex queue.  This can be done in Setup–>Jobs–>Apex Flex Queue.

Asynchronous callouts from Visualforce – An async callout (continuation) can allow you to to make long running requests to external web services and process a response in a callback.  This helps with Visualforce UI’s that may have multiple concurrent requests coming from a larger user base.

@testSetup – can be used to create test records once in a test class and then subsequently used in all unit test methods within that same class.  While this is a great option for setting up test data once keep in mind changes do not span across unit test methods.  After the test method is complete, changes are rolled back when additional test methods run.

Compound fields in Apex – this may be a small change, but one that will greeted eagerly by developers.  Address and Geolocation Compound fields are finally available in Apex.


New Apex Classes:

  • Database.DMLOptions.DuplicateRuleHeader
  • Database.DuplicateError
  • System.Address
  • System.Location
  • System.Continuation
  • A lot of classes under DataCloud

Lightning Components – are still Beta in Spring ’15 but its exciting to see new components and events made available.  Also a list of changed features include:

  • Component markup is now case sensitive.
  • Namespace requirement removed but support added for default namespace.
  • Lightning components can now extend another Lightning component (inheritance).  Also an app can extend an app.
  • Referential Integrity added when editing and saving components.

Components can now be configured to be usable in the Lightning App Builder and Lighting Pages.  You’ll need to implement the interface:

<aura:component implements=”flexipage:availableForAllPageTypes”>

and provide a design file to the component bundle:


<!–attributes here–>




  • Number of deployable/retrievable items have been increased from 5k to 10k files.
  • When (at what point) components are deleted in a deploy (beginning or end) can now be controlled.
  • New attribute for <flow:interview /> “allowShowPause”
  • For the JS utility, and nagivateToRelatedList() method, the relatedListId parameter will now accept the API name of the related list instead of the internal Id.
  • Per the Apex Flex Queue functionality, the existing AsyncApexJob has a new Status field.  Value of holding when in the flex queue.
  • Callout size limit (request or response) increased from 3MB to 6MB (sync) and 12MB (asynch)
  • A tooling api endpoint “apexManifest” is now available to list all apex classes and triggers for an org.
  • ChatterMessage object now supports triggers.


So overall I feel like this is a really decent size release for the platform and developer features.  Many core pieces added and the continued maturation of Lightning being made available to us.  Again this is not all inclusive, make sure you check out the release notes!


My Top 6 Dreamforce Hacks

If you’re attending Dreamforce ’14, regardless if its your first time or you’re a veteran, it feels like every year you learn a new thing or new way to get around the conference and enjoy it.  Here’s my top 6 “hacks” for getting around Dreamforce, hope to see you there!

1.) Getting around.  Chances are unless you are a hardcore developer, you’ll be shuffling around the Moscone Area, Union Square, and other hotels/centers.  Squeezing in a walk between venues in 10-20 minutes can be a challenge given how many people are attending.  My hack, avoid 4th street.  This is the main pipeline down to Moscone from Market and Union Square and back.  It get’s packed, like easily missing the crosswalk packed.  Two alternates routes, go down 5th street and cut over  on Howard, or go through Yerba Beuna gardens (there is a sidewalk from Market St. to Mission St. to get to Yerba Beuna).


2.) Coffee.  Yes this is what powers Dreamforce (along with the cloud), but this too can get crowded quickly.  If you think you’ll be able to dip into Starbucks near Moscone real quick to get your triple vente, 6 pump caramel, 6 pump vanilla, skim milk, with extra whip latte…..think again.  It will be slammed.  Map out your coffee places, and if you’re coming from other hotels or Union Square to the Moscone area, get your coffee on the way.


3.) “Sleep in“.  Dreamforce is a sprint filled with late night networking and all day content, sessions, keynotes, etc.  Pick one day to sleep in a couple hours.  I usually try to target Tuesday or Wednesday, to get up a couple hours later (8am instead of 6am).  It might just be enough to get you through the rest of the week.

4.) Work Time.  There are some attendees, that can go full conference and not have to check-in or work at all.  Bless you, you’re in the minority.  For the rest of us, flag some time (either leave a gap in the schedule, or mark a less than important session) to get you’re work done for the week.  You’ll see many posts about WiFi availability, it always dicey around Moscone, but rock solid at other sites (Hilton, Palace, Union Square, etc.).  So if you can plan a few sessions at those hotels and you can hang around afterwards to knock out your items in your work queue, its a win-win.

5.) Headshots.  If you have any active social channels, or a regular business card dealer, you know a good headshot goes a long way.  What many people don’t know is the Admin Zone offers free photography and headshots at Dreamforce.  If you’ve ever seen any of my head shots, that’s where I got them!  This year the Admin Zone will be in Moscone West.

6.) Session Calendar.  So you finally cut your 100 favorites sessions down to 15 you will actually attend.  Its the day of the conference, WiFi just went down and the mobile app isn’t responding.  Yea it’s happened.  Its hard not to happen with 100k+ people in a 1/2 mile radius.  Make a backup of your session calendar either as a print out or it’s own Google calendar.

Dreamforce Session Google Calendar

Updates 10/1: For the first step and link for the ical, a button has just been made available to download directly from My Agenda, so you don’t have to remember the link anymore.  Also per the 9/30 Road to Dreamforce 14 episode, a release to hide Favorites on export should be made available soon.  So another great option!



It inevitably happens…’re rushing between Dreamforce sessions, trying to find the building and room number of the next one you’re heading to, and for the life of you, you can not get the Dreamforce app on your phone to load.  You reach for your tablet or laptop….but the wifi is also down.  Next you reach into your bag to get the print off you  made, but alas you left it in the room.

This may seem like an extreme Dreamforce scenario……but has happened to me….twice!  The  1/2 square mile at the Moscone area can be a digital war zone.  What I’ve started to do is create a google calendar for my Dreamforce sessions.


  • Its separate, and can be toggled to only see your sessions.  This may be helpful if you have a ton of sessions/appointments.
  • You can store either just confirmed sessions or favorited.
  • You can share just this calendar with people without having to publish your work or personal calendar.
  • Access it offline people!!!!  Great backup to the Dreamforce app and you can get rid of the printout.


  • Not real time, this will only be as good as the last time you’ve imported your sessions.
  • If you want to re-import, you’ll have to delete all the existing calendar appointments (sessions) or just delete the calendar outright…..and have to re-share if you want people to see it (in the case of deleting calendar).


Login to the Success Community and head over to the Dreamforce section.  Then in the browser type in the URL:     You should get a file to download prompt like this:



Now you need to create your Google Calendar, go ahead and login to your Google account and go to Calendar, click on the down arrow next to My Calendars and select Create New Calendar:


Put in your calendar title, details, location, and time zone.  I’ve set my timezone to Pacific because that’s how the times are listed.  When viewing it will covert into your viewing timezone (eastern in my case).



Before you finish creating the calendar you will also have the option to go ahead and share, you can do it now, or go back into the calendar afterwards by clicking on Calendar Settings and Share This Calendar.


After you’ve created the calendar, you’ll be taken back to the main Calendar view.  We want to go to the main calendar settings to import our file.  In the top right you’ll see the gear icon for settings, click on that and Settings.  (note: you can also go this way to create a new calendar)



On the settings page, click on the Calendars link (tab like at the top), and then in the middle  of the page there will be an Import Calendar link.  Once you click on it you can upload the file and select which calendar to import to (one you just created).



There you have it, once you go back to your calendar and timeframe for Dreamforce you’ll see all your sessions and events.  Each will have either (Favorited) or (Enrolled) at the beginning so they are easily identifiable.  As you can see, I have some work to do.



Have fun!