Monday, March 25, 2019

Convert a Person Account to a Business Account with a Flow

Converting a Person Account to a Business Account using Salesforce Flow Builder

If you've worked with Person Accounts in Salesforce, then you know that they can be a great solution for B2C organizations, combining the Contact and Account records to a single 'person' entity. Person Accounts can also be the source of a lot of headaches for Salesforce Admins. One of these potential headaches is converting one account type to the other.

Converting a Person Account to a Business Account (Organization) and vice versa requires manipulating the records directly - and every other blog post I could find discussed using Data Loader to accomplish that. But what do you do if you want to let your users perform the conversion? Or maybe you still want to keep this as an Admin function, but you want to be able to do this from the UI, instead of having to prepare and load CSV's every time this is needed?

Let's talk about a bit of the background and challenges before we get into the actual process of converting them...


Warning - take your bathroom break now!
Since we are creating a Flow with a bunch of elements, and since I wanted to include as much details as possible so that even a new Admin can implement the flow - this post is a little on the long side...

A little background
If you are here, you probably already know what a person account is, why it was created, and some of the history. I will not bore you with these details, and I think there are plenty of places online to find that information.
What is important to know, is what a person account is: an account marked as a Person Account (where you'll see isPersonAccount = true), is actually two records: an Account record and a Contact record.
The Account is the parent of the Contact record (just like a Contact and Account relationship in a standard Business Account) - but because the Account is associated with a Person Account record type - Salesforce makes them behave differently, and displays both records as a single page.
More than just the presentation on the page - the contact record's fields are actually available on the person account's account object and to clarify that those are actually the Contact fields, they are suffixed with '__pc' (instead of the normal '__c').
There are some 'standard' Account fields that are not available when an Account is designated as a Person Account. For example, the Account Name field is not available, as you are expected to use the Person Account's First Name and Last Name fields.
The same happens with the Shipping and Billing addresses, which are not available, and instead you must use the Contact's Mailing and Other addresses.

How do we convert one to the other?

The actual process of converting a Person Account to a Business Account, or vice-versa, is not too complicated, though it requires a little more knowledge and messing with the records' data. In fact, the only way to convert them is by updating field values that are not accessible through the UI. It all boils down to updating the RecordTypeID field on the Account object, though there are some considerations:

Considerations for converting a Business Account to a Person Account
  1. You must know (or find) the RecordTypeID for a Person Account
  2. As the Account and Contacts are merged, the Contact name will override the Account name
  3. The Business Account must have only one contact
  4. You are only allowed to update the Record Type ID in the update, without any other fields. Any other field updates must be done separately.
  5. The conversion will not work if the account has been enabled for communities or portals
Considerations for Converting a Person Account to a Business Account
  1. You must know (or find) the RecordTypeID for a Business Account
  2. You are only allowed to update the Record Type ID in the update, without any other fields. Any other field updates must be done separately.
  3. The conversion will not work if the account has been enabled for communities or portals.
For a FULL list of all considerations, take a look at See page 13 in the implementation guide for all of the considerations: https://resources.docs.salesforce.com/218/latest/en-us/sfdc/pdf/salesforce_B2C_implementation_guide.pdf.

So now that we know all this - let's dive into the Flow will allow your users to do this conversion from the UI...

** Big thank you to Cari Aves, Salesforce product manager extraordinaire, for correcting a couple of the above considerations and providing the link to the implementation guide **

Building a Flow to convert a Person Account to a Business Account

This flow has 8 Elements in it. Since I am going to provide a full step-by-step insturctions, this post is very long... Let's walk through this process, step by step.
One thing to note: I am assuming here that you only have one Business Account and one Person Account record types. If you have more than one of each, you'll need to tweak this flow to either select the right one, or add a screen to let your users select the correct record type.
  1. Go to the Setup page, and find the 'Flows' tab
  2. Click the 'New Flow' button to start building our flow.
  3. You are now on the Flow Builder page with an empty flow.

Creating Element #1: find the RecordTypeID for the Business Account.

See the pictures below the step-by-step:
  1. Drag the 'Get Records' element to the flow, and name it 'Get Business Account Record Type ID'
  2. Select the 'Record Type' as the object
  3. Set the Filters to:
    - isPersonType Equals False
    - SObjectType Equals 'Account'
  4.  Leave the next 3 options with their default values
  5. Under the Select Variable to Store Record Type:
    - Click the '+ New Resource'
    - Select 'Variable'
    - Give it an API name and description
    - For Data Type, select 'Record'
    - For Object select 'Record Type'
    - Click Done
  6. Click on the 'Record Variable' box again, and select the variable you just created.
  7. Under the 'Select Record Type Fields', add the 'Name' field
  8. Click Done
Get Record:


New Resource:
Woo hoo! You created the first element!

Creating Element #2: Get the current Account's Company Name

Once you 'break apart' the Account and the Contact, you will end up with an Account that has the same name as your Contact. We'll want to update the Account Name to match the original Person Account's Company name - so we'll have to get it first.
  1. Drag another 'Get Records' element to the flow, and name it 'Get person account's company name'
  2. Select the 'Account' object
  3. Set the filter to:
    - Id EQUALS, and click 'New Resource' on the value field
  4. On the new resource:
    - Choose the Variable Type
    - Name it 'RecordId' 
    ** The recordId variable name is reserved and will automatically be assigned the id of the record from which we will launch the flow later**
    - Select the 'Text' data type
    - Leave the Default Value empty
    - Select the 'Available for Input' checkbok
  5. Scroll to the 'Select Variable to Store Account', click on the empty box, and then Create New Resource again
  6. In the New Resource window that opens:
    - Resource Type: Variable
    - API Name: originalAccount
    - Description: Store values from the original account
    - Data Type: Record
    - Object: Account
    - Click the Done button
  7. When you go back to the previous window, click the empty box again, and select the 'originalAccount' variable we just created.
  8. Finally, under the 'Select Account Fields to Store in Variable' section add the 'Company__pc' field
Here's what this all should look like when you are done:
Get Record Element:


recordId resource:


originalAccount resource:



OK... we're making progress, but there's more to be done!

Creating Element #3: Assign the Company name to a variable

We want to store the company name in its own variable so we can show it later, after updating the account.


  1. Drag an Assignment element to the flow
  2. Label it 'Save company name'
  3. Under 'Set Variable Values' click the Search Variables and then... you guessed it: '+ New Resource'
  4. Under the new resource window, select:
    - Resource Type: Variable
    - API Name: companyName
    - Data Type: Text
    - Click Done
  5. Click on the 'Search Variable values' again and select the newly created companyName variable
  6. Set the operator to Equals
  7. Under Value, select the 'originalAccount' variable, and then select the 'Company__pc' field.
    This will store the value from the account on the variable we just created.
  8. Click Done
Again, this is what it'll look like:
Assignment Element:

companyName variable:



Creating Element #4: Update Account Record Type

Now that we have all this information ready, we can finally go and update the Record Type on the Person Account to convert it to Business Account. Remember, we are only allowed to update the RecordTypeId, and nothing else. 
  1. Drag a new Assignment element to the flow
  2. Label it: 'Assign Business Record Type to Account'
  3. Under Variable, select the originalAccount variable, and then the RecordTypeId field
  4. Set the operator to Equals
  5. On Value, select the 'businessRecordTypeId' variable we created on the first element, and then select the 'ID' field
  6. Click Done
This is how it'll look:



Creating Element #5: Commit Account Changes

Now that we've assigned the new record type id to the account record, let's go ahead and commit it to the database:
  1. Drag an 'Update Records' element to the flow
  2. Label it: 'Commit new RecordTypeID'
  3. Under Select Variable, choose our 'originalAccount' variable
  4. Click Done.





You could stop here.
If you are just looking to change the account from a Person Account to a Business Account - you only need the first 5 elements. But the end result is an Account that has the same name as the Contact. If you want to Account Name to be updated, you need to continue with the next 3 elements.


Creating Element #6: Confirm Company Name


There are three reason we want our users to confirm the company name:

  1. The 'Company Name' field on the person account may not have been what the user actually wants the account to be named
  2. We can only use Flows with a screen component when creating a quick action
  3. The only way to separate the commit of the Record Type ID from a commit for the Account Name update is to have a screen between the two record update components. Without a screen, the Flow will 'collect' all the record updates and perform them all together at the end - and as we know, we cannot update anything beyond the record ID when changing from Person to Business accounts.
With that in mind, let create our element:

  1. Drag a Screen element to the flow
  2. On the right side, label the Screen: 'Convert a Person Account to a Business Account'
  3. Drag a 'Text' component to the screen
  4. On the right side:
    - Label: 'Company Name'
    - Require: Checked
    - Default Value: Select the companyName variable we created in element 3
  5. Click Done



Creating Element #7: Update Account Name


Let's assign the Company name that was provided in the previous screen to the account:

  1. Drag an Assignment Element to the flow
  2. Label it 'Assign Account Name'
  3. Under Variable, select the 'originalAccount' variable, and then the 'Name' field
  4. Set the Operator to Equals
  5. Set the Value to our Company Name screen component
  6. Click Done


Creating Element #8: Commit Account Name Update


Finally, we can now commit the new account name to the database:

  1. Drag an Update Record element to the flow
  2. Label it 'Commit Account Name Update'
  3. Under the Variable, select our 'originalAccount' variable
  4. Click Done

We are done creating elements! There are a few more steps to take...



Connecting all the elements

Now that all the elements are present, we need to connect them to create the order of operations. Just drag the little circle on each element to the one following it, in the same order as we created them. Start by connecting the 'Start' element to the 'Get Business Record Type ID' element
When everything is connected, it should look something like this (the placement of the elements on the page doesn't actually matter):


Save the Flow:


Click the 'Save' button:

  1. Label: 'Convert Person Account to Business Account'
  2. Description: 'Let users convert a person account to a business account with a contact'
  3. Type: Screen Flow
  4. Click Save

Activate the Flow

Before the flow we just saved can be used, we need to activate it.
To do that, click the "Back" button at the top of the Flow page. You should be navigated back to the Flows page, showing the list of flows.

Find the 'Convert a Person Account to Business Account' flow, and click on the flow label.
On  the screen that opens, you'll see the 'Flow Versions' list at the botton. Click the 'Activate' button next to the version of the flow that you want to activate.

Note: Once you activate a flow, you cannot edit it. When you edit it it will always save as a new version, which means you'll have to go back here to activate the new version. Until you do that, the previously activated version will continue to be used.

Create a Quick Action


We want our users to be able to launch this flow from the Person Account page.
To do that, we'll create a quick action.
  1. Navigate to Setup > Object Manager > Account > Buttons, Links, and Actions menu
  2. Click 'New Action'
  3. In the New Action page:
    - Action Type: Flow
    - Flow: Convert Person Account to Business Account
    - Label: Convert to a Business Account
    - Name: Convert_to_a_Business_Account
  4. Click Save


Add the Quick Action to the Person Account Page Layout


Last Step!
Let's add this button to the Person Account page layout so that it is visible to our users:


  1. Navigate to Setup > Object Manager > Person Account > Page Layouts
  2. Click on the Page Layout you want to edit
  3. On the left section, select 'Mobile & Lightning Actions' (Not 'Quick Actions')
  4. Find the 'Convert to a Business Account'
  5. Drag it to the top of the page
  6. Save the page layout



Let's test this baby!

You did it!
Let's test this now, by opening up a person account and attempting to convert it.
Notice the 'Person Account' title on the page layout:

Now click the 'Convert to a Business Account' button:
Watch the Flow's screen pop-up with the Company Name from the person account:

Note: While we haven't yet confirmed the company name, be aware that by the time this window pops up - the Account Record Type ID has already been updated. So even if you close this window, it will have been converted already - just not renamed.

Confirm the Company name and click Next.

We are now navigated back to the account, but now the title is 'Account' and the Account Name is 'Acme':

When we navigate to the Related List tab, we can see the Contact is still there with its original name

That's it! 

I hope you found this post helpful! Please post your thoughts in the comments - I'd love to hear if this helped you and what you think.

9 comments :

  1. Great post Ohad! We used to do this with Javascript buttons, but since they aren't supported in Lightning it's great to see an option available for the new experience!

    I will make one correction and one addition to the information you posted: a business account and contact don't need to have the same name to be converted to a person account. The contact's name will override the existing business account name upon conversion. It is also important to note that the conversion process will not work if the account has been enabled for a community or portal. This tends to be a big gotcha for customers. See page 13 in the implementation guide for all of the considerations https://resources.docs.salesforce.com/218/latest/en-us/sfdc/pdf/salesforce_B2C_implementation_guide.pdf.

    ReplyDelete
  2. This is a great post. Thank you. Do you have a flow that could help with converting a "Business Contact" to a Person Account?. It's impossible to convert a Lead to a Person Account and a Business Account. It's either, hide the Company field or convert to a Contact and a Business Account.

    ReplyDelete
    Replies
    1. You are correct- when the Lead record has a company name, it will always be converted to a business account.
      I haven't created a flow yet for converting a business account to a person account, though it should not be very different from the one described above.
      You'd change the RecordTypeID element to find the Business record type you are interested in (or if there are several, you can get all and let the user pick the right one with an extra screen).
      You would also want to create another element to verify that the account only has one contact.
      If I have time over the next couple of weeks, I'll try to create that and post a separate blog post.

      Delete
    2. Awesome! I know others that have an issue with this. It is especially a big problem with the Financial Services Cloud because the model uses the Leads object for Referrals. Banks typically have business Leads/Referrals or Person Leads/Referrals.

      Delete
  3. In element 2, step 8, i dont have the Company__pc field available, only Contact__PC. Is that the same? Can i use that instead?

    ReplyDelete
    Replies
    1. Didnt work.
      using "Account Name" field neither

      Delete
    2. Hi - I'm really not sure why you are not able to see he Company__pc field - have you verified that your profile has field-level-access to this field?

      Delete
  4. Hi Ohad,
    In the second step, can we just use the screen element to let User input the company name? Because not all the person accounts have the Company name filled before converting

    ReplyDelete
    Replies
    1. Johnny,
      You are absolutely right - several users have reached out and only then I realized that the company__pc field was actually a custom field we created...
      I plan to update the blog post over the coming weekend to accommodate for this - but the short answer is yes - you can skip the step where we get the value from company__pc field and just use the screen element alone!

      Delete