Keep your Automation Simple

I’ll start this off by saying I’m guilty of not always keeping it simple.  But, I strive for simplicity.  Just because you can build something in Salesforce 10 different ways, doesn’t mean all 10 of those ways are right.  The solutions we implement often have a great deal to do with the skills and budget your Org has available.  Back when I was a Solo Admin, I was very guilty of duct taping together solutions, because the alternative solution was to have nothing.  We didn’t have the budget to hire developers for all of our ideas.

The purpose of this post is to discuss how we can simplify our solutions to make them easier for us to comprehend and maintain.  We’re going to walk through this set of requirements our project champion gave us:

  1. On Closed Won Opportunities, Alert Accounting with an Email
  2. Automatically Create a new Project for our Account Manager to run.
  3. Update the Account Owner to be the Account Manager
  4. Alert the Account Manager of their new Project, with a link to take them straight to the project.

Let’s take a first pass at solving this…

kiss-option-1

This accomplishes everything that we were looking to do.  We can now send the project champion a note saying that it has been completed… right?  Hold on!

Looking at this solution from end-to-end, how easy is this going to be for me to maintain?  On the surface, it’s pretty basic, but would an outsider easily comprehend it?

Let’s take another pass at simplifying it…

kiss-option-1b

We were able to simplify our automation by putting the Email Alerts into the Process Builder and Flow.  This looks easier to maintain and understand than our first process.  I would be tempted to call it quits here, but I think we could simplify the process further.

So, let’s take one last pass at simplifying this…

kiss-option-2

I’m feeling pretty good about this now.  Everything is in one location, and I can see all of my automation around this scenario in one spot!  Personally, I would go with our third and final solution if I was going to implement this automation.  Don’t go crazy and (when possible) and have Workflow Rules, Process Builder, Flow, and APEX all working together for one piece of automation.

How to Optimize your Process Builder and Quick Action Speeds

Process Builder and Actions (Quick Actions) are two of my favorite declarative tools that Salesforce has.  I’ve had a few posts on Actions and how powerful they can be when you add in Process Builder and even sometimes Flow.  I’ve also specifically had a few posts on how to write your Process Builders so that you can optimize them for speed (read here).  Now, this idea on today’s post does go against the concept of having One Process Builder per Object, but I think it does pose a good argument against it.  That argument is SPEED!

I’ve seen scenarios where we want to use Actions to create record(s).  What if you want to create an Action that creates an Opportunity, which in affect you want to have the Opportunity Team dynamically updated, and maybe a few Tasks automatically assigned to the new Opportunity Owner?  This is all stuff that a simple Process on the Opportunity Object will run perfectly, right?  Yes.  However, that automation can bring your Action to a crawl.

The Influence

The inspiration for this post comes directly from some of my work in Apex.  I discovered what Future Methods were when writing some really fun code a while back.  In short, it just attempts to perform the action in the future, as opposed to during your current transaction (creating or updated a record).  This allows you to bypass some limits that you might have otherwise had.

The Solution

By moving our Actions from the Immediate Actions to Scheduled Actions and placing the Set Time to 0 Hours After [date field] to ensure that it fires almost instantly after the record creation or update.

Schedule 0 Hours.png

After setting the time, add in your Actions.

schedule0hours

Advantage

The real advantage here is speed.  By being able to delay certain actions from taking place in the transaction, you’re able to increase your save times.  The result is a faster experience for your End Users.  I don’t think I need to add anything to that 🙂

flash-2.png

Disadvantages & Considerations

I’m aware that the list of disadvantages for the one advantage might comes off like one of those drug commercials with 30 seconds full of side affects… but here we go 🙂

The biggest disadvantage to me is that the record(s) that you might be creating or updating won’t be “ready” instantly.  If the User using the Action is also the one whose expecting some of those Actions to happen automatically, then maybe it isn’t the best solution for them.

As I mentioned at the start of this post, this does go against the One Process Builder per Object design pattern.  If you have a scheduled action, you’re not able to do the “evaluate next” inside your Process.  That post, like this one, is not a mandate that you must follow.  As the Admin/Dev running your Org, you should be able to make an educated decision on what is best for your scenario.

The last consideration around implementing this is understanding its impact on testing.  It is much harder to test something that happens in the future.  This affects your manual testing and any Apex Test Classes.  I would be surprised if you didn’t have any scheduled actions in your Process Builders and Workflow Rules… so it isn’t like this type of action isn’t being used today by many of us.

Putting it all together

The goal of this post is to not say you must use delayed Process Builder actions.  It is simply to add one more tool to your tool belt for when you’re working with Process Builder and Flow.  These concepts are not one-size-fits-all… adjust the concepts to fit your Org.

How to use Case Comments with Communities in the Service Console Feed View & Salesforce1

This past week I had someone who is looking to use Case Comments in the Service Cloud, but wanted it to be listed as an Action in the Feed.  I thought it would be a good use case of many different tools within Salesforce being used together.  I am looking at possibly doing this with code and basing it off this post, but for now I figured that I’de show you how without code.  Let me be clear that if you’re not using a Community that you can simply use the Internal Comments field instead without having to do anything.  The only negative of going with this solution is that you’re not going to have your Case Comment Chatter Post visible until your Chatter feed is refreshed, but that is something that also happens with the Internal Comments field.  The Case Comment record is visible instantly.  And this works nicely with Salesforce1.  With that said, let’s jump right in!

Automation Overview:

  1. Inputs for Case Comment received (Action)
  2. Process Builder triggered (Pass inputs into Visual Flow)
  3. Case Comment created in Flow

For this solution we have two different options in how we can do it architecturally:

  1. Record Create – Create new Custom Object
  2. Record Create – Create new Task Record
  3. Record Update – Use Custom Fields on Account/Opportunity

For me, because of not wanting to further complicate the Task Object and not wanting to add excess fields to the Case Object, I’m going to go with option 1 and create a new Custom Object.

How will we build this?

  1. Create the Case Comment Extension Object
  2. Create our Visual Flow to create the Case Comment
  3. Create our Process Builder to launch the Visual Flow
  4. Create our Action on the Case

For this solution we have two different options in how we can do it architecturally:

  1. Record Create – Create new Custom Object
  2. Record Create – Create new Task Record
  3. Record Update – Use Custom Fields on Account/Opportunity

For me, because of not wanting to further complicate the Task Object and not wanting to add excess fields to the Case Object, I’m going to go with option 1 and create a new Custom Object.

What fields do we need create in this Custom Object?

  1. Auto Number
  2. Case (Master-Detail)
  3. Comment (Long Text Area)
  4. Public (Checkbox) Note: this only applies if you have a Customer Community.

CaseCommentExtensionObject

Let’s get our Flow created first since we can’t Activate the Process Builder without it  (Setup | Create | Workflows & Approvals | Flows).

NewFlow.jpg

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

RecordCreate1.jpg

We now need to create the variables we will use to create the Case Comment.

Case Id

CaseCommentParentIdVariable

IsPrimary (This is a BOOLEAN, not Text)

CaseCommentIsPublishedVariable

CommentBody

CaseCommentBodyVariable

Lets make sure everything is correctly mapped inside our Record Create.

CaseCommentCreation

Great!  So lets hit OK and set this as our Starting Element.

SetAsStartElementCaseComment

Now lets drag in our Record Delete.  This is so that we don’t add useless data into Salesforce.

RecordDeleteDrag

Create a variable for the Record Id of the Custom Object record we just created, when our Action is used.

var_CaseCommentExtensionId

Map it in our Record Delete.

DeleteCaseCommentExtension

Connect the elements together to finish our Flow.

FinishedFlow

And lastly we want to Save and then Activate our Flow!

SaveCaseCommentFlow

ActivateCaseCommentFlow

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

CaseCommentExtensionPBCreation

We want the Process Builder to fire on our Custom Object that we created, Case Comment Extension, and we want it to fire only when a record is created.

CaseCommentExtensionPB1

We don’t need to set any criteria here, but to be safe let’s just make sure that we have a Case ID and Comment before proceeding.

CaseCommentExtensionPB2

Now we need to map the variables in our Flow to the Values in the Custom Object, using the Type Reference.

CaseCommentExtensionPB3

Hit Save, then Activate your Process Builder. Now, lets navigate to go create our Action.

CaseCommentActionNewButton

Keep it on the default, Create a Record, and select Case Comment Extension (our Custom Object we created earlier).

CaseCommentAction1

Let’s make sure we turn off the Create Feed Item, so we don’t spam the Chatter Feed since the Case Comment itself will cause a Feed Item to be created.  Also, make sure we add in a nice Success Message and custom Icon to make the action look sharp!

CaseCommentAction2

Remove the Case Field and drag Public and Comment into the Action’s Page Layout.  Make sure you require the Comment field.

CaseCommentAction3

It will give you a small popup warning you about not having the Case field on the Layout, but you can ignore it and move on.

CaseCommentAction4

We now need to setup a Predefined Field Value for our Case field.

CaseCommentAction5

Set Case.Id to our custom Case field.

CaseCommentAction6

Now all that is left is for us to update our layout(s)!

CaseCommentActionToLayout

And with that, lets take a look at the finished product!

CaseCommentAction.png

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).

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

The “One Process Builder Per Object” Design Pattern

Ever since the Summer ’16 release notes dropped, the Salesforce Community has been going ecstatic over the one and only Process Builder improvement.  The Community is so excited with this one feature, that I have not seen anyone complain about Process Builder only had one improvement.  The reason is this improvement is a game changer in the Process Builder world, and it will change the way that we build our Process Builders.

ReleaseNotesImageEvalNextCriteria

Note: Evaluate the Next Criteria has one limitation currently.  It doesn’t work with Scheduled Actions (which makes sense).  So, if your Process Builder has a Criteria that includes Scheduled Actions, you’re out of luck for continuing any further down the Process Builder (and that particular Process won’t really apply to this Blog Post).  So keep in mind during this post that any Process Builder with a Schedule Action can’t be included.

Unable to do Scheduled Actions

One Process Builder to Rule them All!

TheOneRing.jpg

You’re probably asking yourself why would we want to build an extremely long Process Builder?  This idea comes from attempting to mirror the Apex Trigger best practice and design pattern.  Yes, there are additional benefits to this design pattern with Apex as opposed to Process Builder, but the main points still ring true.

#1 – Keep it Simple

No longer do you need to search through tons of Process Builders trying to understand what all is going on behind the scenes.  You’ve got all of your logic in one spot for you to look at (excluding Scheduled Actions).  Heck, Salesforce even mentioned how it makes it easier in the release notes!

release notes.jpg

#2 – Control Your Order of Execution

pemdas.jpg

So, just like with your Order of Operations, it is important to be able to know what order you execute Process Builder actions.  However, unlike the Order of Operations where we can follow a consistent process every time… with Process Builder we don’t know which order our Process Builders will execute in.  If we have 15 different Process Builders on the Cases Object, then we have no control over what order they will be executed.  It is quite scary when you realize you’ve got zero control over the order your Process Builders run in!

With executing multiple criteria in a single Process Builder we are now able to consolidate all of our Process Builders into just ONE.  And, in our one Process Builder we can drag and drop our actions around into the desired Order of Execution.

For a quick summary, creating one Process Builder to rule them all will allow you to simplify your Process Builders for each Object, and will allow you to have consistency in the way your actions are fired.  Do you have to do this?  No, there is nothing stopping you from continuing to build Process Builders in the same fashion that we previously did.  But, I would ask you to consider thinking about incorporating this design pattern into your Orgs once it becomes available.

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!

How to bypass User Permissions with Flow

Have you ever come across a permission limitation that you couldn’t solve using a Permission Set?  Every once and a while we get requirements that can test the limits of what we can technically do with Salesforce.  It might be a Field Level Security issue, or it might be a License limitation.  Before Process Builder was around, if you wanted to get by some sort of limitation like this, you had to write code.  Not anymore!  Process Builder runs in the context of the System.

So… when Visual Flow is that when its autolaunched by Process Builder, it too will run in the context of the System and not the Running User.  This means any Field Level Security, Profiles, Roles, or License type can essentially be ignored.  Think of an Autolaunched Flow as temporarily giving somebody temporary Admin access.  Where this can get interesting is when we start to think of all of the different ways we might use this!

ProcessBuilderIcon

Get creative!  You can do all sorts of cool things to bypass Licenses and Security  issues by using Autolaunched Flows.  Here are a two examples to get you thinking:

Site.com Guest User Access

In this scenario we want to send an email to our clients to propose that we close a Case, and in that email present them with a Yes and No button.  If they click the button you want the Case to properly react.  That means we need to have that button click send them to a specific URL (associated to our Site.com) with a unique parameter that matches to our Case.  The problem is we are unable to have an unauthenticated User edit a Case.  We can give the Site.com Guest User access to Create on a Custom Object, and have that Custom Object then trigger a Process Builder to run and find and edit the Case.  There are some obvious security issues, but they can be solved by building your parameter and Flow correctly.

Add and Remove Permission Sets and Public Groups

We want our Marketing Manager to be able to add and remove people to a Permission Set and/or Public Group.  We can create a Checkbox or Picklist on the User Object, and have an edit to that field trigger a Process Builder to launch our Flow where we either add or remove them to the Permission Set and/or Public Group.  Access to this field can be then controlled by a Permission Set or by Profile.  With this, we can essentially delegate any Admin function to any User without given them Admin privileges!

How to track the Case Age of each Status

I’ve been running into many scenarios where people want to track the Age of each status (be it Case or another Custom Object).  We’ve got things like Field Tracking that we can use to get close, but the data isn’t very easy to build dashboards and reports on.  So, my mind immediately went back to one of my first posts and Flows, Case Time Tracking.  In this post we were wanting to see how long the Users had worked on a Case, and not how long our Cases were staying in a status.  But architecturally we’re going to be pretty similar.

Automation Overview:

  1. Case Meets Criteria – Process Builder triggered (Pass inputs into Visual Flow)
  2. Flow Checks to see if existing open Record
  3. Flow Updates existing record if possible
  4. Flow Checks to see if Case is still Open, exists if Closed
  5. If Case is Open, Flow creates new Record

We will be creating a few fields on our Custom Object:

  1. Case [Master-Detail Lookup]
  2. Start Time[Date/Time]
  3. End Time [Date/Time]
  4. Status [Picklist – Mirror Case’s values]
  5. Minutes [Formula, Number, 2 decimals]

For our Minutes Formula we want to use this:

IF ( ISBLANK ( End_Time__c) , 0 , ( End_Time__c – Start_Time__c ) * 1440 )

Depending on your business case, you might want to change this to be Hours or Days instead of Minutes.  Also, you might want to make 

Here is what our finalized Object looks like:

Case Age 2

Now that we have our Object ready, we can go create our Flow (Setup | Create | Workflows & Approvals | Flows).

NewFlow.jpg

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

RecordLookup.jpg

We are going to be doing a Lookup on our Custom Object we just created to track the Status Ages.  We want to first check to see if one is already open on this Case, and if we need to stamp the open record with an End Time.  If not, then we can ignore going to a Record Update and go to a Record Create if the Case Status is not closed.  For our Record Lookup, we need a variable for our Case’s Id and our Existing Status Age Id (our new Custom Object).

var_CaseId.jpg

StatusAgeId

Which gives us our Record Lookup.  If you notice, we are using IS NULL with the Start and End Date fields.  We simply want to find a record that has a Start Date but doesn’t have an End Date.  That would equate to being an open record that we need to update with an End Dat

Record Lookup for Case Status Age.jpg

Set the Record Lookup as our Start Element

startElement.jpg

Now, we want to drag a Decision Element into our canvas to determine if we found a Record in our Lookup or not.

Add Decision to Flow.jpg

Call the Decision Element “Existing Record?”.  For our first Decision Criteria or Outcome to be checking to see if our variable of the Case Status Age is null or not.

Decision in Flow.jpg

Now, we want to drag in a Record Update element to update the existing Case Status Age record, if we found one.

DragOutRecordUpdate.jpg

We will want to use for our criteria the Id of the record we found in our Lookup.  For the fields we will update, we want to use the System variable, CurrentDateTime

RecordUpdateCaseStatusAge.jpg

Update End Date.jpg

Now, lets drag out another Decision Element.  We need to determine if our Case is Closed or not.  If it is Closed, we don’t need to create another record.  If it is Open, then we will create another Case Status Age record.  So, lets call the Decision Element “Case Closed?”.

AnotherDecision.jpg

We want to create a variable called var_CaseIsClosed that will be passed in from the Process Builder.  Note: this is a BOOLEAN field.  We will check to see if var_CaseIsClosed is FALSE.  If so, we will proceed to our Record Create, but if it is TRUE we will let it exit the Flow.

CaseIsClosedBoolean.jpg

CaseIsClosedDecision

Hit OK, and we now get to map our elements together.  Notice, we map our Record Update to our second Decision Element.

MapDecision.jpg

Now we need to drag out a Record Create.

DragOutRecordCreate.jpg

We need to create a variable called var_Status, which just like var_CaseIsClosed, will be passed in through our Process Builder.

var_Status.jpg

We now will setup our other inputs on the Record Create to be our Case’s Id and the Start Date (which we will use the System Variable again).  This is our last element of the Flow, so we don’t need to assign the Record ID to a variable.

CreateCaseStatusAge.jpg

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

FinalizedCaseStatusAgeFlow.jpg

Lastly we want to Save and then Activate our Flow!

SavedFlow.jpg

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)

NewPBCaseStatus.jpg

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

CaseStatusPB.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() || ISCHANGED([Case].Status)

CaseStatusChanged

Now we get to setup our Immediate Action of launching a Flow.  All we need to do is pass in our Case Id, Case Status, and our IsClosed field.  Note: the IsClosed is listed as Closed in Process Builder.  IsClosed is the API Name for that field.

Set Case Status

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