How to Simplify the “One Process Builder Per Object” Design Pattern by Using Custom Settings

About three months ago, as we were getting ready for Summer ’16, I posted The “One Process Builder Per Object” Design Pattern.  On that post, my friend Chad Seales commented on asking how you would manage One Process Builder for a whole Object, because one benefit of having separate Process Builders is that you can Activate or Inactive any of them as you need.  He brought up a very good point, and one I had somewhat overlooked before the post.  So we’ll go over how to do just that by using Custom Settings!

Concept Overview:

  1. Create Checkbox Field on your Object
  2. Create Custom Setting
  3. Create Checkboxes on your Custom Setting for each “Process Group”
  4. Reference the Custom Field and Custom Setting in your Process Builder to determine if your Criteria is Active or Inactive.

Navigate to your Object and create a Custom Field with the type Checkbox.  Make sure the Default Value is Checked/TRUE.  For my example I’ll be working on the Opportunity.  I’m going to call this field Process Builder Active.  Make sure to leave a nice description so that any other Admin will know what this field is being used for.  Note – if you’re in an Object with existing records, you’ll have to populate this Checkbox as TRUE through a data load (Default Values do not work retroactively).

Custom Field for PB Active

Navigate to create a Custom Settings (Setup | Develop | Custom Settings).  Select New.

Custom Settings.jpg

You’ll want to make sure that you select Hierarchy as your Setting Type.  If you want additional information on the difference between List and Hierarchy, check out Salesforce’s documentation.

Hierarchy

It is time to click New and add in the different Process Groups or Criteria that you want to control.  For each of these, you’ll want to create a Checkbox Field.

Opportunity Custom Settings.jpg

Hit the Manage button.  This takes us to what I call the “record” of the Custom Setting.

Opportunity Custom Settings.jpg

We then want to hit the New Button.  This is where we will determine if those Checkboxes are TRUE or FALSE.

Default Org.jpg

Check the boxes for the Process Groups you want Active.

Check Boxes

Simple as that… we’re now done with our Custom Setting (until you need to add another Process Group down the road).  Head over to Process Builder, and lets talk about using our Custom Setting values in our Process Builder.  We need to add a final condition to our Criteria.  So, lets add the Custom Field we created Process Builder Active.

Selecting PB Active Field

Select Formula as the Type.

Selecting Formula

Select the System Variable search tool.

System Variable.jpg

Hit $Setup and then select the Process Group Checkbox that you want to use.  Note – $Setup is where all your Boolean Custom Settings fields live inside of Process Builder.

Selecting Checkbox

All that is left for you now is to hit Use this Formula!

Using Formula

For a quick summary, we are used Custom Settings to house the Active Status of our different Process Groups (what used to be individual Process Builders).  This allows you to turn on (or off) specific Criteria inside your Process Builder off without affecting the whole Process Builder!  If you’re being a good Admin and doing this in your Sandbox – note the “record” in your Custom Setting won’t deploy with your Change Set.  You’ll have to manually update that (or through data loader if you have more than 3 checkboxes).

Five Best Practices for Building a Clean Visual Flow

We’ve all been there, where you’re learning to write your first Visual Flow.  The main thing we’re focused on is just making sure that it is functional.  That’s fine while you are in your Sandbox developing, but once you’ve got it working correctly you need to make sure your Flow follows these five best practices.

Elements are Organized

One of the top rules for writing code is using proper indentation.  David Liu (SFDC99) is known for his love (or OCD) of clean code.  Visual Flow’s equivalent to indentation is the alignment of the elements into a clean format.  Think of it like you’re having company over – you would make sure you cleaned your house up before they arrived.

Your Flow should be very easy for you to follow the Flow Elements from start to finish without having to strain your eyes.  Keeping it clean also lets your Flow be easier to make future updates to it.  You don’t have to take apart your Flow to make sure you didn’t miss anything on your update.  So, be sure you spend the extra minute or two to make sure your Flow is sharp looking!

Bad

Messy Flow

Good

Sharp Flow

Naming Convention

In the developer realm, camel Case is the standard.  In Flow, we’re stepping into the developer world without really having to write code.  It obviously isn’t required that you use camel Case as your naming convention, but it is important that you follow a consistent naming convention.  If you don’t, your Flow will be much harder to read.

camel.png

Variable Names

In addition to your naming conventions, you need to make sure your variable names make sense.  I have opened up way too many Flows that use variable names that are not clear. If someone has to do some detective work to figure out what your variable is doing, you need to rethink your variable naming.  Variable naming can often be hard to do correctly, because you have to summarize the function of the variable into a small concise variable.

DoCaseId — Don’tRecordId

Why? RecordId is very generic and does not tell me what Object it is referring to.  I would have to go find where the value was assigned to see the Object it is the Id for.  CaseId is clear and I don’t have to do any research to figure out what it is.

Fault Messages

When your Flow fails its important for everyone to be alerted.  If you’re a Solo Admin, then you can technically get away without using a Fault Message, because Salesforce’s Email Alert will go to you.  However, if you have more than one person developing in your Org, this is a requirement! By setting up a Fault Message, you can easily alert all of the Admins and Developers of the issue.

It is also important to use multiple Fault Messages inside your Flow.  You’re able to customize the Email being sent out to provide specific information that pertains to that particular part of your Flow.  This will help you as you troubleshoot your Flow.

Fault Message

 

Descriptions

Make sure you use Descriptions in your Visual Flow.  This goes along with having your Flow Elements all aligned and easy to read.  You want your Flow to be easily digestible.  It is important to not write blatantly obvious Descriptions, just to write them.  You want to make your Descriptions helpful.

Anytime you have to do something unique inside your Flow you should include a Description to explain what, and more importantly why.  An example would be when you use a Formula in your Flow.

Description.png

 

 

Recap: Think long term when you’re building your Flows (or anything).  Just like you want to create a good User Experience for your End Users, make sure you create a good one for the Admins & Developers that are maintaining the Org.  None of these best practices require a significant amount of time to follow, and the benefits of having a clean Flow will be worth the extra effort!  And if you’re still reading, make sure you check out my The 6 Most Common Visual Flow Errors to Avoid.

 

 

Introduction to Salesforce Actions

Salesforce Actions are one of my favorite tools.  If you’ve got a group of Users that are heavily using Salesforce1, then you can really be a rockstar for them by understanding how to use Actions correctly.  But, Actions also work in Chatter Feeds, Quick Actions, and Lightning Experience!  While Buttons are not extinct, Actions are the future and you should look at using them!

salesforce_lightning.jpg

Global Actions

Where can these be used?  These can be used on any Record Detail Pages & Home Pages… so anywhere an Action can be.

Actions

Can be used on Record Detail Pages for the specified Object.  The biggest difference between a Global Action and an Action is an Action allows you to preform a Record Update.

Global Actions vs Actions

Global Actions allow you to build an Action that can be used across multiple objects!  This means, if you have a specific Record Create, Visualforce Page, or Custom Canvas that you want displayed in multiple spots (or maybe just on the Home Page), then this is your best option.  With the Global Action you are able to re-use your Action across multiple areas, which means it takes less effort to develop and is easier to maintain!

Quick Action (Classic) vs Salesforce1 & Lightning Experience

Ability to have different layout for Salesforce Classic compared to Salesforce1 & Lightning Experience.  When Salesforce added Lighnting Experience they did not group it into the Quick Actions layout, but instead added it to the Salesforce1 Action layout.  So, if you currently are using Lightning Experience, the layout (at this time) will have to be the same between desktop and mobile.  Down the road Salesforce might split this up into a new layout so that we can once again have different actions for the Desktop than our mobile devices.

Action layouts for each object are predefined by Salesforce, but you are easily able to override and drag-and-drop Actions around in the layout (just as you would a Field).  If you customize the Quick Actions (Classic) layout, but not the Salesforce1 & Lightning Experience layout, then the Salesforce1 layout will mirror the Quick Actions layout.

Actions Layout.jpg

Each Action has its own Layout (Works with Record Create, Record Update, and Log a Call)

One nice thing about Actions is how easy it is to drag-and-drop the fields that you want to be displayed for your Action.  Pretty powerful!  Combine with Predefined Values and you’ve got the ability to really streamline the experience!

Your Layout.jpg

Predefined Values (Works with Record Create, Record Update, and Log a Call)

With Actions, one of the biggest selling points is the ability to use Predefined Field Values.  This allows you to save your End Users time entering information (just as you would ‘pre-populate’ fields with a button URL hack).  You’re able to reference the Object that you’re on (if applicable), and the System Fields like the Running User and Custom Settings.  If you choose to display these values on the Action Layout, the End User can change the default value if needed.  If you don’t need the End User’s input, then simply remove it from the layout and the Predefined Field Value will do the rest.

Predefined Value.jpg

Action Design Considerations

Have you noticed that both Global Actions and Actions allow for you to select Log a Call as a type of Action?  All this really is doing is setting some predefined fields/layout changes for you, but it is still a Record Create of a Task.  The benefit, besides not having to set some of those predefined values, is that you get a beautiful Custom Icon!  When you are creating your Actions, be it a Visualforce Action or a simple Record Update, make sure that you’re using the Lightning Design System to use an appropriate Icon.  User Experience matters!
Lightning Design5

Lightning Design6

As of the Spring ’16 Release, we have the ability to now use Success Messages for our non-coded Actions (Record Create, Log a Call, and Record Update)!  This is something small (just like picking a Custom Icon), but it really does enhance your the User Experience of your Action.

Success Message 1

Success Message 2

Sometimes the Chatter Feed can get annoying if every little thing done shows up.  This issue  was also resolved with the Spring ’16 Release, giving us the ability to choose whether or not we want to Create Feed Item with our Action for any Record Create (includes Log a Call).

Create Feed Item

 

How to work with Related Records in Process Builder Criteria

When Process Builder first came out, the lack of error messages made it hard to adopt.  I have noticed from looking at the Salesforce Answers Community, confusion with Process Builder errors is a very common.  In this post, we will cover one of the most common mistakes for someone learning Process Builder – how to work with related records.

What do I mean by related records?

Anything that is referenced through a Lookup Field on an Object (including System fields like Created By).

lookupfield.jpgWhen you’re working inside Process builder, you’ll see a chevron next to any related object that you can navigate to.  This lets you then reference the fields of that Object in your Criteria and Actions.

RelatedRecords

This works like a charm, until you decide to have a Process Builder reference a Lookup Field that is not populated (so the value is null).

failed.jpg

Yikes!  We never want to see that error stopping an End User from saving a record!  What happened?  Salesforce will tell you in your Fault message (emailed), the variable “hasn’t been set or assigned.”  What does that really mean though?

You were trying to reference a related record, but your Lookup Field does not have a value or record in it.  This isn’t documented very well, and is an easy mistake almost everyone will make as they learn to use Process Builder.  This is a new problem for Admins, because we do not run into this issue with Formula Fields and Field Updates (in a Workflow Rule).  And, this is a serious problem because it actually can affect an End User’s ability to make a new record and/or edit an existing record.

So now that we know the problem, how do we fix it?

  1. Check for Null
  2. Formula Field

Checking for Null is the approach that I prefer to go with.  Either one can technically work, but I choose to keep my Objects as simple as possible and avoid adding excess fields.

For our example, lets say that we wanted to run some automation for our Opportunity when the Primary Campaign is Type = Trade Show.   We’d first need to make sure that our Opportunity actually has a Campaign associated to it, otherwise we’d get that failed to execute the flow error.  So, how do we do it?

Campaign ID >  the Related Record, ability to reference Campaign Fields.

Campaign ID  the Campaign Lookup Field on the Opportunity.

CampaignLookup.jpg

 

That means that the Campaign ID Field houses the value of the Lookup.  Which means we can check to see if there actually is a value!

SelectCampaignId

CheckforNull

Now, we are able to add the rest of our conditions that reference our related Campaign record.

Note – we must to check for Is Null BEFORE we reference the related record’s fields.  Salesforce checks our criteria from Top to Bottom.

typetradeshow.jpg

We can now reference fields on related records in Process Builder because we first validated that we had a related record.

Understanding how to write Process Builder Criteria

I am working on a mini-series related to understanding Bulkification (related to Process Builder and Visual Flow).   So, you’re going to see a theme of posts like this and Building your Process Builder for Optimum Performance and Bulkification where I focus on some design considerations with Process Builder and Flow.  The reason behind these posts are because Process Builder and Flow are extremely powerful tools that give those previously developer-only powers to the masses.  And as we all know… with great power comes great responsibility!  So, lets do our part to make sure that we build our Process Builders and Flows in a way that would not cause developers headaches.  I’ll cover the basics of the different types of criteria, and then go over why it matters that you take building criteria seriously.

spiderman1.jpg

When setting the criteria for our Process Builder to fire, our options are:

  1. Conditions are met
  2. Formula evaluates to true
  3. No criteria – just execute the actions!

Lets dive deeper into each of these and talk about when and why would use them, and some of the common mistakes that are made around these.

Conditions are met

criteriapb.jpg

Using this as our criteria gives us a few more options than what we used to have with Workflow Rules criteria.  Now, we have operators like Is changed and Is null that were previously unavailable to us.  Outside of those new options it is essentially just a cleaner UI.  Don’t forget about the ability to make your Value a Formula (see condition #3), you can use awesome functions like PRIORVALUE and grab in cool System things like your Custom Settings!  Speaking of, Jennifer Lee has a great post on using Custom Settings in Process Builder that is a must read for anyone not familiar with Custom Metadata or Custom Settings!

Conditions.jpg

So we can pretty much do pretty much everything inside this criteria option… but what are the pitfalls that we will run into?

Forgetting to check the Advanced checkbox.

I really wish that Salesforce didn’t hide this section, it needs to be front and center!  I feel like this is one of the biggest errors that people make when building a Process Builder.  It is often overlooked until you’ve got a Process Builder that is creating a record or sending an email, and you realize that you’ve just had six emails get sent out to a Client!criteriaadvanced.jpg

Using Is changed

While I absolutely LOVE this operator that Salesforce gave us within Process Builder, the fact of the matter is I have seen tons of Success Community questions where people get stuck on this.  It isn’t documented very well that Is changed will ONLY run on Updates.  This will not run on Create.  That means, you’re up a creek without a paddle if you’re trying to build your Process Builder to only fire when a value changes, but also have it work if that field has been filled out on create.  If anyone has a clever way that they’ve found to bypass this issue, I’de love to hear it.

Formula evaluates to true

criteriapb2.jpg

While not as simple as the conditions are met option, this gives us the ability to do everything that we would want to do.  The problem is that this often is more fragile than the rest.

API Field Name Changes

This option unfortunately will NOT update your formula if you have to change the field name.  Keep this in mind, because just about everywhere else in the UI this is something we’re accustomed to.  You will however be greeted with a lovely error message anytime you try to Clone ur Update your Process Builder

errormsg.jpg

Is changed for new records works!! kinda…

Here is a simple example of how you could use the formula evaluates to run on new records and still run ischanged on updates.

We essentially have separated our criteria into On record create and On any updates.

(ISNEW() && NOT(ISBLANK(field)) || ISCHANGED(field)

In my below example I only have to use ISNEW() because the Case Status is always filled out.

ischanged.jpg

No criteria – just execute the actions!

criteriapb3.jpg

This should not be used unless you have a very good reason.  Just because we have a simple action does a Record Update and nothing else does not mean that we want it to always fire on every edit.  This means that every single edit our Process Builder is firing.  How many situations can you think of that actually require a Process Builder to fire every single time?  Don’t be a lazy Admin and use this option just because you can!

Why does this matter?

Because of how Salesforce ‘bulkifies’ our Process Builders and Flow!

bulk.jpg

https://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_forcecom_process_bulkification.htm

The issue is that as we continue to customize an Object with more and more Process Builders and Flows you keep adding to the string length!  Remember that every simple Record Update in your Process Builder, no matter how simple, counts as an actual query that will be added into that ‘bucket’.  Previously with Workflow Rules you never had to worry about those simple Field Updates running on every edit of the record, but now as we try to keep our Process Builders and Flows bulkified it becomes an issue!

By fully understanding our Process Builder’s criteria (and using it correctly), we are able to cut back on the extraneous actions.  This results in two big things:

  1. Reduced process time when you hit Create or Edit a record
  2. You’re more bulkified due to a decreased the number of queries

Which means you’re now the hero of your Org!

hero.jpg

How to let a non-Admin EASILY assign Permission Sets and/or Public Groups

Once and a while you get into the situation where you want a non-Admin User to manage a few specific Permission Sets and/or Public Groups.  Let me start this off by saying Delegated Administration is a fantastic option to use.  However, I’ve run into the scenario where that sometimes doesn’t do the trick.  If you’re dealing with someone non-technical this type of Admin work can be a difficult End User experience.  One of the most often times I do this is working with special permissions for Community Users.  That is because Community Users don’t even have Public Groups visible on their User Detail!  So, if the manager has administer more than type of group or assignment, it is easy for them to make a mistake.  So, how can we make this as easy of an experience as possible and help to reduce errors?

Simple, we use a Checkbox (and sometimes a Picklist)!

checklist

In this post we are going to go over my method of simplifying how you can assign Permissions by using a field on the User Object that any User can be given access to.  Let me reiterate why I do this:

  1. Makes it dummy proof.  It takes the thought out of the End User managing the Permission.  All your End User needs to do is Check or Uncheck a box (or select a different picklist value).  There is less of a chance for them to add or remove the wrong permission.
  2. A List View cam show your End User who has (or hasn’t) been given the permissions they’re assigning.  This makes it easy for them to see whose been given the appropriate access, and they don’t have to go into the Permission Set, Public Group, Queue, or Chatter Group to verify they’ve removed or added someone.
  3. Easier training for the Admin.  It isn’t as hard to train someone to check a box or use a picklist!

Ok, so now that we have established why I think this is a great solution, lets get rolling!

For this example we are going to go use a Checkbox to assign a Permission Set to a Community User.  The Permission Set will be granting access to our Knowledge Article Type that is only available for our Premier Support customers (similar to Salesforce’s Premier Support).  To do this, we need to create a Checkbox on the User Object, and make sure we only give access to the appropriate Users (assign via Profile or Permission Set).

Note: while we are only assigning a Permission Set in this example (to keep it simple), you can easily add on using this same blue print and swapping out the Object to whatever Object you need.

Automation Overview:

  1. User Record Meets Criteria – Process Builder triggered (Pass inputs into Visual Flow)
  2. Flow Checks to see if existing Permission Set Assignment
  3. Flow Determines if we add or remove the Permission Set Assignment
  4. Flow adds or removes the Permission Set Assignment

We will be creating:

  1. Premier Support [User Field – Checkbox]
  2. Flow to run our logic
  3. Process Builder to launch our Flow

So start off by creating your new Checkbox field

Premier Support.jpg

Now that we have our Premier Support Checkbox created, we can go create our Flow (Setup | Create | Workflows & Approvals | Flows).

NewFlow.jpg

The first step is going to be grabbing our Record Lookup.

Record Lookup1.jpg

We are going to be doing a Lookup on our Permission Set Assignment Object.  We want to see if we have a matching Permission Set Assignment or not.  We will want to setup our criteria, and set an ID if we find a Record.  To do so we will need to have these three variables created:

var_UserId – The Id of the User the Process Builder is triggered from (passed in from PB)

var_UserId.jpg

var_PermissionSetAssignmentId – The Id of the Permission Set Assignment, if the User has been assigned the Permission Set already.

var_PermissionSetAssignmentId.jpg

var_PermissionSetId – The Id of the Permission Set associated to Premier Support (passed in from PB)
var_PermissionSetId.jpg

This will give us a final Record Lookup that looks like this

Finished Record Lookup

Great, now lets set this as our Start Element

Set Start Element

Now, we need to setup a Decision to see if we need to add or remove the Permission Set assignment.  So, lets drag that out to our Canvas.

DragDecisionOut.jpg

We will need to have a variable for our Checkbox field.  So lets create that and call it var_PremierSupport.  Make sure you set it to the Type of Boolean.

var_PremierSupport.jpg

Now, lets setup our Decision Criteria.  The first one will be if we want to ADD the Permission Set to the User, we want to check to make sure the var_PremierSupport EQUALS TRUE and the var_PermissionSetAssignmentId IS NULL is TRUE

Add

The second one will be if we want to REMOVE the Permission Set from the User, we want to check to make sure the var_PremierSupport EQUALS FALSE and the var_PermissionSetAssignmentId IS NULL is FALSE

Remove

If for some reason we don’t meet either of those criteria, we are going to leave it be and let it exit the Flow (because something is wrong).

Note: You probably want to setup some sort of Fault email to be sent to yourself so that you know there was an issue (possibly an Admin assigning the Permission Set already), but hopefully that won’t ever happen.

Now, lets drag out our Record Delete.  This will be for when our record matches our Remove criteria.

Record Delete.jpg

This is an easy Element to setup.  We just have to select the Permission Set Assignment Object and then map our Id to the Id field.

DeletePermissionSetAssignment.jpg

After we save this Element, make sure you map your Decision to it with the Remove outcome.

Now, let us drag out a Record Create.  This will be for when our record matches the Add criteria.

DragRecordCreate.jpg

Great, now we just need to select our Permission Set Assignment Object and then map our var_UserId and var_PermissionSetId fields.

RecordCreate

Now, we need to map our Decision to the Record Create.

FinalFlow.jpg

Lastly we want to Save and then Activate our Flow!

SaveFlow

Note: I like to append “- Flow” to my Autolaunched Flows.  This makes things clearer when I am dealing with them on the backend since Flow and Process Builder both are in the Flow metadata folder.

ActivatedFlow.jpg

Fantastic!  Now we need to setup our Process Builder that launches this Flow.  So lets go create a new Process Builder for this.  (Setup | Create | Workflows & Approvals | Process Builder)

CreatePB

We want the Process Builder to fire on our Account, so for our object select User, and for starting the process select when a record is created or edited.

SetUserObject.jpg

Now we need to setup our Criteria.  Unfortunately an ISCHANGED function doesn’t run on new Cases.  So we have to break out the formula editor and use this formula:

(ISNEW() &&[User].Premier_Support__c = TRUE)  || (ISCHANGED([User].Premier_Support__c))

 

ActionCriteriaPB.jpg

Now we get to setup our Immediate Action of launching a Flow.  All we need to do is pass in our User Id(Reference), Premier Support (Reference), and Permission Set ID (String).

Note: we are to breaking my hard coding an Id rule for this example.  I would recommend that you pass in the Permission Set Name and query for the Permission Set ID in your Flow.  I am ignoring that because I want to keep this blog post simple.

Launch Flow

Hit Save, and then hit Activate up in the top right corner… and you’re done!

Salesforce Admin vs Consultant, Whats the difference?

Before I took the plunge into the consulting world, I was an internal Salesforce Administrator and Developer working in Sales Operations.  I was in charge of a 200 user Salesforce org.  We used both Sales and Service Cloud, and we even had two Customer Communities.  Since my jump to become a Consultant I’ve noticed that some skills transferred over and others didn’t.  In this post I’ll make 5 comparisons between a Salesforce Admin/Dev to a Salesforce Consultant. Continue reading