A few months ago I did a post on creating a Conditional Auto Number using an Autolaunched Flow. In the comments, I mentioned that you could actually solve the solution using only Process Builder. It seemed like that idea had some interest from people, so I wanted to turn it into a post. With Salesforce (for better or worse) there are so many ways that we can accomplish the different solutions we come up against.
- Account Meets Criteria – Process Builder #1 triggered (Record Create Action)
- Custom Object Record with Auto Number created – Process Builder #2 triggered
- Update the related Account record with the Auto Number value
What fields do we need create in this Custom Object? Just one! A Lookup to Account. Also, we need to make sure we set the Name to be an Auto Number.
HINT: If you ever need to reset the number, you can switch the Name field to Text and then back to an Auto Number and it will let you pick the Starting Number again.
Here is what our finalized Object looks like:
Now that we have our Object ready, we can go create our first Process Builder (Setup | Create | Workflows & Approvals| Process Builder).
We want the Process Builder to fire on our Account, so for our object select Account, and for starting the process select when a record is created or edited.
This next step is completely on you for when the record meets the criteria. For my example we will just use when the Type is now a Customer. Careful with the Advanced section at the bottom, you aren’t going to want your Process Builder to fire more than once per Account!
Now we get to setup our Immediate Action of creating our Client Number record. All we need to do is pass in our Account Id.
Hit Save, and then hit Activate up in the top right corner… and lets move on to our next Process Builder!
We want the Process Builder to fire on our Client Number Object, so for our object select Client Number, and for starting the process select only when a record is created. We don’t need to do this action any other time. Tip: if you’ve got something you need to run on Create, but you have more than one Process with it you can always use IsNew() in your criteria.
Since this is the only action we will have on the Client Number Object, and we know the Account will always be filled out, you might want to use the No criteria – just execute the actions! option. However, I chose to validate that I first have found an Account value, because strange things can happen.
Now we get to setup our Immediate Action of updating our Account record with the correct Client Number value. We need to make sure we set this to update on the Account Object. If you notice, I didn’t choose the Account> option, because that would be if I wanted to update a record related to the Account.
All that is left for us is to set the Account Number to be updated with the reference to our Client Number’s Auto Number value.
Hit Save, and then hit Activate up in the top right corner… and you’re done!