How to Create a Conditional Auto Number with just Process Builder

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.

Automation Overview:

  1. Account Meets Criteria – Process Builder #1 triggered (Record Create Action)
  2. Custom Object Record with Auto Number created – Process Builder #2 triggered
  3. 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.

AutoNumberObject.jpg

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:

customobject

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

createpb2

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.

PB1.jpg

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!

NewCustomerCriteria.jpg

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.

pb6.png

Hit Save, and then hit Activate up in the top right corner… and lets move on to our next Process Builder!

createpb1

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.

pb2.png

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.

pb3

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.

pb4

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.

pb5

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

14 thoughts on “How to Create a Conditional Auto Number with just Process Builder

  1. Paul Fennell August 30, 2016 / 9:36 pm

    I love the way you think. I’m trying to mimic this scenario for use on Leads, but I’m running into a problem in tying the custom object record to the Lead ID that created it in Step 1.

    I noticed in step 1 you’re setting the field “Account” for your custom object to the ID of the Account that is involved in the flow. However, I don’t see this field on your custom object summary- could you elaborate.

    My workaround was to create a field on my custom object with a child-master relationship with Leads, that didn’t seem to work.

    So ultimately running into a problem in updating my Lead record with the correct Client Number value. I’m not entirely sure I’m tying the lead object to my custom object so I can’t find the Client Number value as an option to update with that value.

    Like

    • David Litton August 30, 2016 / 10:54 pm

      Hey Paul,

      Using the Flow I don’t need to use the Account ID. I just need the Auto Number to be generated and then the Flow grabs that value and populates it to the Account.

      Using the Two Process Builder option I need to create and pass in the value of the Account ID so that the second Process Builder can update the related record through a Record Update. A small variation due to the fact that Process Builder can’t query like Flow can.

      Let me know if that doesn’t help you get in the right direction and I can see if I can help further.

      Thanks!

      Like

      • Paul Fennell August 31, 2016 / 6:25 pm

        Thanks much David, this is such a valuable resource and I appreciate your time.

        I’d love to take you up on the offer to review this process over screenshare, and would be happy to Venmo you for your time.

        So a couple takeaways:

        1) So I notice in the last Step of #1 you are setting the field Client_Number.Account to reference the Account.ID of the object that created this record. This makes total sense, however, could you elaborate on the field type of Client_Number.Account?

        You see in the beginning you noted one only need create the auto-number field as the object standard field for name, however, it appears I do need to create the “Account” field on my custom object to store the ID of the Object that kicked off this workflow.

        2) So I’m still equally a little challenged with step 2.

        When I choose to update the record related to my custom object (in this case Lead), I do not see the option to choose any fields from the Lead object.

        This leads me to assume that somehow I need to create a relation from my custom object to the object that kicks this thing off in the first place (Lead is created or edited).

        Hope this makes sense, and again thanks for the inspiration and your time.

        Feel free to shoot me an email at p.flannel@gmail.com to arrange some time to put this to rest.

        Thanks!

        Like

  2. Paul Fennell September 1, 2016 / 5:18 pm

    Hi David, I figured it out!

    I needed to create a lookup to the Lead on my custom object. I populated the Lead.ID in step 1 to this lookup field, and in step 2 I used a formula function to update the lead record with my autonumber from the custom object.

    Thanks so much for the inspiration here, I know have conditional round robin for lead assignment which is beyond dope.

    Like

    • David Litton September 1, 2016 / 6:53 pm

      Paul,

      Glad to hear you were able to figure it out yourself, and that this post was able to push you in the right direction! Let me know if you have additional questions on it!

      Like

      • Ahmad Helal (@WhatTheHelal) September 21, 2016 / 11:04 pm

        David, this is exactly what I needed, however I noticed that in the beginning of this blog you say that the custom object needs no fields, when in fact it does need 1 field (the lookup field to account) — otherwise the 2nd process would never work b/c no relationship would exist. That’s why Paul was confused.

        I think you need to update the 1st part of your blog to make this more explicit.

        Like

      • David Litton September 25, 2016 / 6:58 pm

        Ahmad, thanks for the feedback! You’re right, that was a mistake on my end with how the post started. I’ve made an update so that it is accurate now.

        Like

  3. Carol Ardell (@carol_ardell) December 16, 2016 / 8:30 pm

    Hi, I had been working on a conditional auto number for my opportunity page. It will be called Sales Order # and it will be an auto generated number only when the Opportunity is Closed Won. No numbers will be generated unless the opportunity is closed won. I created a custom object (auto generated number) for my opportunity page called Sales Order Number. When I go to Flow and create a Record – I’m not sure what to select under assignments, as the Sales Order Number I created does not show up. What do I select? Thanks for your help!! the instructions are great, but I can use some help!! -Carol

    Like

    • David Litton December 19, 2016 / 5:31 am

      Hi Carol, you need to have a Lookup on the Sales Order Number Object to the Opportunity. That would be the only field that you fill out when you’re creating the record, as the Name (auto generated number) would be filled out automatically for you. Your second Process needs to have the Opportunity ID so that it can go update the recently Closed Won Opportunity with the Sales Order Number after it gets created. Let me know if that doesn’t make sense.

      Like

  4. crenard February 21, 2017 / 10:06 pm

    Thanks for writing up this great idea, David! Nice clear explanation.

    I’ve just used it to create a Membership Number on Contact based on someone enrolling in a workshop session. I had to generate the first process off the Enrollment custom object (since that’s the record that’s changing), but because it also has a lookup to Contact, the relationships carry through.

    I could have done the Flow version, but having a custom object that is just a list of Membership Numbers assigned to Contacts will be useful for reports.

    Just what my client has been looking for 🙂

    Like

  5. Justin Williamson August 29, 2017 / 2:50 pm

    I’m trying to replicate this process on a Lead object, but I’m not having any success. I have followed your steps exactly. Is there something about the Lead object that makes this process different?

    Like

    • David Litton September 6, 2017 / 3:23 pm

      No, there shouldn’t be. Let me know if you’re still running into an issue, easiest to contact me on twitter.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s