I always try to avoid hard coding record type ID's into workflow because then they break when deployed to production. Lets say for instance I want to update an account with a new record type, well process builder will only let me specify as update Account Record Type ID to 00hj00000073CL. I am going to use flow so I can use the record type name and make this dynamic and not break across orgs. My workflow will update an account record type to "Company" whenever a checkbox titled "Company" is selected on the account.
First, we need to create a record lookup. The object we are looking up is Record
Type. In short, we are going to lookup a
record type based off a variable (RecordTypeName) that we will reference in process
builder instead of using the ID. Once the record is found, we are going to take
the ID and assign that to a variable.
So first we are looking up a record type where name equals a variable we create. For value, select
Variables and Create New. Name the
variable and then select input only and save.
Next we are going to assign the ID of that to a new
variable. Create a new variable like above and then hit OK.
Next is where I am going to update
the account record type. Drag a record
update and name it. We are going to
update Account and we have to say which account we are updating. We are going to create a variable for account
ID and then in process builder tell the system that the record that process
builder is firing on will be the record we are updating. So choose ID for field and create an Account
ID variable like before.
After that is where we get to update the
record type. We are going to update the
Record Type ID with the RecordTypeID variable we created earlier. Remember, the record lookup will lookup to a
record type based off a record type name variable that we will set in process
builder. Once it has that record type it
will assign it’s ID to an ID variable which will then be used in the record
type update.
Connect the two elements and click the little plus sign on
the record lookup to set it as a start element.
Save your flow, don’t forget to activate it.
Now to process builder to tell this to fire this flow when the Company checkbox is checked. Create a process off of Account and
have it start when a record is created or edited. Then for the criteria, it will be Company
(Checkbox I created earlier) = True. Now
to tell the Flow some information. On immediate actions select Flow then select the one you created earlier.
We need to tell the process builder where to get the values
for two of our variables. First, on our
record update we need specify what vAccountID is so the flow knows which account to
update. We are going to reference the
Account ID that the process is firing on.
Next, this is how we can now use a name for a record type
instead of an ID. This flow/process will
still work when deploying to production!
We will set it to a text string and type in the record type name. Save and activate and test.



No comments:
Post a Comment