Error when converting a Lead to a new Account Record Type - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Randy HenryRandy Henry 

Error when converting a Lead to a new Account Record Type

My Government Sales organization wants to start using leads the same as our other sales team. Right now, they only use their own Account Record Type. Currently Leads are converted over to Person Accounts. I have followed the steps in knowledge article 000004504 and 000004455 to map a new field over to the Government Account Record. It still works fine when I do a standard sales to Person Account conversion (the default on my profile - no change when I modify that), but I am receiving an error when I do the Lead to Government Account Record conversion.

I did create different Lead Record Layouts, and I have checked and added the required fields in the Government layout that do not exist in Person Accounts. However, I'm getting a rather nebulous error. It appears that it has issues with the Converted Status, but the error is less than helpful as I have had other errors anchored on that same field when tweaking settings that I knew would fail as further tests. The error message I am receiving is below:
Error: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, A workflow or approval field update caused an error when saving this record. Contact your administrator to resolve it. Record Type ID: value not valid for the entity: PersonAccount: [] (System Code)

The knowledge articles I used for reference are: https://help.salesforce.com/apex/HTViewSolution?id=000004455&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000004455&language=en_US) and https://success.salesforce.com/answers?id=90630000000gpSpAAI.

As I have been doing largely exploratory updates (try, backout, try something else) as I inherited this configuration, I have kept a log of all the changes I made. Those changes are listed below in case they will help someone see what I have and have not done.

Create and Map Fields
  • Create a field called "What record type?" on the Lead. It is text 25, isn't visible, and isn't on any page layout.
  • * Create the same under Accounts.
  • * Under Build > Customize > Leads > Fields > Map Fields, map the "What record type?" field in Lead to the Account counterpart.
  • * Build > Create > Leads > Fields, add a new field called "Govt Account Type" of type Picklist with the values of State and Federal.
  • * Build > Create > Leads > Fields > Map Fields, map  the Lead Govt Account type with the Account.Govt Account Type.
  • * Add the text fields State Account Type, State Employer Type, and Other State Employer Type. Make all text 25. Map all to their Account counterparts.
  • * Add the text fields Federal Agency Type and Other Federal Agency Type. Make both text 25. Map both to their Account counterparts.
Existing Field Updates
  • * Updated the "Lead Line of Business" field to not have a default and sort alphabetically.
  • * Updated "Lead Line of Business" to be viewable by all (read-only for the Read Only profile).
  • * Added "Lead Line of Business" to the Lead Page Layout and put it just above "May we contact you?"
  • * Set "Lead Line of Business" as required.
Main Build / Configure
  • In Build > Customize > Leads > Lead Processes, create new Lead Processes for Government and MA Sales.
  • In Build > Customize > Leads > Record Types, create new record types for MA Sales and Government. Make sure that MA Sales is available for all but the Government Profile. Make sure that Government is only available for the Government, IT Support, Business Development, and System Administrator profiles. Set defaults accordingly.
  • Update the Government User Profile Object Settings for Lead to have the Government Lead type as default.
  • Update the Business Development, System Administrator, and IT Support Profile Object Settings for Lead to have the Government Lead type as available.
  • Clone the Lead Layout and named it "Government Lead"
  • In Build > Customize > Leads > Record Types, click on Page Layout Assignment. Click Edit Assignment and change all of the Government column to the Government Lead page layout for all profiles.
  • Edit the MA Sales Record Type for the Lead Line of Business field to make MA Sales the default value. Remove the Government option.
  • Edit the Government Record Type for the Lead Line of Business field to make Government the default value. Remove the MA Sales option.
  • Put the Govt Account Type in the Build > Create > Leads > Page Layouts for Government. Make it required.
  • Build > Create > Workflow & Approvals > Workflow Rules, add the following rules:
    •     Populate Lead Record Type Name
      • Object = Lead
      • Criteria =  Lead: What record type? equals null
      • Field update workflow action
        • Object = Lead
        • Field to update = Lead.What record type?
        • Formula Value = RecordType.Name
    • Populate State Reqrd Fields
      • Object = Lead
      • Criteria = Lead: Govt Account Type EQUALS State
      • Field update workflow action (State Account Type)
        • Object = Lead
        • Field to update = Lead: State Account Type
        • Field Data Type = Text
        • Formula Value = "Other"
      • Field update workflow action (State Employer Type)
        • Object = Lead
        • Field to update = Lead: State Employer Type
        • Field Data Type = Text
        • Formula Value = "Other"
      • Field update workflow action (Other State Employer Type)
        • Object = Lead
        • Field to update = Lead: Other State Employer Type
        • Field Data Type = Text
        • Formula Value = "Update Required"
    • Populate Fed Reqrd Fields
      • Object = Lead
      • Criteria = Lead: Govt Account Type EQUALS Federal
      • Field update workflow action (Fed Agency Type)
        • Object = Lead
        • Field to update = Lead: Federal Agency Type
        • Field Data Type = Text
        • Formula Value = "Other"
      • Field update workflow action (Other Fed Agency Type)
        • Object = Lead
        • Field to update = Lead: Other Federal Agency Type
        • Field Data Type = Text
        • Formula Value = "Update Required"
    • Populate Account Record Type Person
      • Object = Account
      • Criteria =  Account: What record type? not equal to Government
      • Field update workflow action (MA Update)
        • Object = Account
        • Field to update = Account: Account Record Type
        • Field Data Type = Record Type
        • Field Value = Person Account
    • Populate Account Record Type Govt
      • Object = Account
      • Criteria =  Account: What record type? equals Government
      • Field update workflow action (Govt Update)
        • Object = Account
        • Field to update = Account: Account Record Type
        • Field Data Type = Record Type
        • Field Value = Government Accounts
Best Answer chosen by Marija (Salesforce) 
Randy HenryRandy Henry
Thank you both for your responses. It has been a hectic week with other projects, so this is my first opportunity to get back on this. (Go Saturday workdays!) 

Sindoora,
I have created different Lead Record Types to eventually map to the appropriate Account Record Types. I also cloned the Lead Page Layout and assigned them accordingly just for consistency with the Account setup. When a user creates a new Lead, they have to choose between MA Sales (which currently maps to Person) and Government (which is what I want to map elsewhere). After running the code and watching it in the Developer Console, I got the execution log, but it pretty much said the same as I was seeing through the UI.

Chidambar,
I didn't think that Company was being set anywhere, so I made the field visible on the Lead just to see. It isn't being set at Lead creation. I then checked the workflow rules and couldn't see any field update. I also checked: Lead Field Mappings, Flows, Account and Lead Triggers, and the Process Builder. Nothing seems to touch Company. Additionally, if I switch the MA Sales Lead Record Type to point to Person Account, it works. It's when I point MA Sales to Business Account or I point Government to Government that it fails with the log errors listed below. Consequently, if I tell Government Leads to point to Person Account, it works fine. 

After talking through these two items, I had an idea. 

The issue I had, Chidambar, was just the opposite of what you had outlined. So, I added a workflow rule to populate Company if the record type was Government (the only one that doesn't end in a Person Account). Worked like a charm!

Thank you both.

All Answers

Sindoora GopagoniSindoora Gopagoni
May be the below rule causing the error Object = Lead
Criteria =  Lead: What record type? equals null
Field update workflow action

when creating a Lead you will have to choose record type.without record type you can't enter a lead .

To find exact bug open developer console and run the process again. The debug log will give catch the bug causing error.
Chidambar ReddyChidambar Reddy
Hi Randy,

When you have Person Accounts enabled in your organization.
and when you a try to convert a Lead
  • with Company(Standard) field populated in it, it tries to create a Business Account but your workflow is trying to set the Record Type to Person Accounts which is invalid for Business Accounts.
  • without Company(Standard) field populated, it will be converted as Person Account.

Make sure that you have no company populated in your lead, you may use a custom field to store the lead company information and move the value from Standard Company field to Custom field and you may map them to Person Account fields.
Randy HenryRandy Henry
Thank you both for your responses. It has been a hectic week with other projects, so this is my first opportunity to get back on this. (Go Saturday workdays!) 

Sindoora,
I have created different Lead Record Types to eventually map to the appropriate Account Record Types. I also cloned the Lead Page Layout and assigned them accordingly just for consistency with the Account setup. When a user creates a new Lead, they have to choose between MA Sales (which currently maps to Person) and Government (which is what I want to map elsewhere). After running the code and watching it in the Developer Console, I got the execution log, but it pretty much said the same as I was seeing through the UI.

Chidambar,
I didn't think that Company was being set anywhere, so I made the field visible on the Lead just to see. It isn't being set at Lead creation. I then checked the workflow rules and couldn't see any field update. I also checked: Lead Field Mappings, Flows, Account and Lead Triggers, and the Process Builder. Nothing seems to touch Company. Additionally, if I switch the MA Sales Lead Record Type to point to Person Account, it works. It's when I point MA Sales to Business Account or I point Government to Government that it fails with the log errors listed below. Consequently, if I tell Government Leads to point to Person Account, it works fine. 

After talking through these two items, I had an idea. 

The issue I had, Chidambar, was just the opposite of what you had outlined. So, I added a workflow rule to populate Company if the record type was Government (the only one that doesn't end in a Person Account). Worked like a charm!

Thank you both.
This was selected as the best answer