function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DBA/DeveloperDBA/Developer 

Trigger error message - CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, record type missing for: Account

I am trying to develop a trigger to automatically convert Lead record into an Account record.  I had code
working before I requested Person Account to be activated in my Developer Edition to match my Enterprise Edition.
Now I get the following error message:
 
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger LeadToAccount caused an unexpected exception, contact your administrator: LeadToAccount:
execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0;
first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, record type missing for: Account: Trigger.LeadToAccount:
line 54, column 9
 
The trigger code is included below:
 
trigger LeadToAccount on Lead (before insert) {
 for (Lead lead : System.Trigger.new) {
  System.debug('lead = ' + lead);
  Account LeadAccount  = new Account();
  LeadAccount.Account_Group__c = lead.Account_Group__c;
  LeadAccount.Affiliate_Code__c = lead.Affiliate_Code__c;
  LeadAccount.RD_Age__pc = lead.Age__c;
  LeadAccount.AnnualRevenue = lead.AnnualRevenue;
  LeadAccount.Assistance_to_build_your_portfolio__c = lead.Assistance_to_build_your_portfolio__c;
  LeadAccount.Booking_Code__c = lead.Booking_Code__c;
  LeadAccount.Business_Code__c = lead.Business_Code__c;
  LeadAccount.BillingCity = lead.City;
  LeadAccount.Company_Name__c = lead.Company_Custom_field__c;
  LeadAccount.BillingCountry = lead.Country;
  LeadAccount.DateofFirstContact__c = lead.DateofFirstContact__c;
  LeadAccount.Description = lead.Description;
  LeadAccount.PersonDoNotCall = lead.DoNotCall;
  LeadAccount.PersonEmail = lead.Email;
  LeadAccount.PersonHasOptedOutOfEmail = lead.HasOptedOutOfEmail;
  LeadAccount.E_minis_Global_Workshop__c = lead.E_minis_Global_Workshop__c;
  LeadAccount.Fax = lead.Fax;
  LeadAccount.PersonHasOptedOutOfFax = lead.HasOptedOutOfFax; 
  LeadAccount.FirstName = lead.FirstName;
  LeadAccount.RD_Income__c = lead.Income__c;
  LeadAccount.Industry = lead.Industry;
  LeadAccount.LastName = lead.LastName;
  LeadAccount.PersonLeadSource = lead.LeadSource;
  LeadAccount.Lead_Source__c = lead.Lead_Source__c;
  LeadAccount.Mail_Opt_Out__pc = lead.Mail_Opt_Out__c;
  LeadAccount.PersonMobilePhone = lead.MobilePhone;
  LeadAccount.NumberOfEmployees = lead.NumberOfEmployees;
  LeadAccount.RD_Other_Investment_Interests__c = lead.Other_Investment_Interests__c;
  LeadAccount.Phone = lead.Phone;
  LeadAccount.PO_Box__c = lead.PO_Box__c;
  LeadAccount.RDPhonecall__c = lead.Q1_Would_you_like_receive_a_phonecall__c;
  LeadAccount.RDLearnStockMarket__c = lead.RDLearnStockMarket__c;
  LeadAccount.RDLearnInvestProperty__c = lead.RDLearnInvestProperty__c;
  LeadAccount.RDLearnInternetBusiness__c = lead.RDLearnInternetBusiness__c;
  LeadAccount.RDLearnInvestor__c = lead.Q3_Someone_investing_on_your_behalf__c;
  LeadAccount.RDEmploymentStatus__c = lead.Q4_Current_employment_situation__c;
  LeadAccount.Q5_Total_assets_less_total_liabilities__c = lead.Q5_Total_assets_less_total_liabilities__c;
  LeadAccount.Rating = lead.Rating;
  LeadAccount.Referral_Code__c = lead.Referral_Code__c;
  LeadAccount.Salutation = lead.Salutation;
  LeadAccount.BillingState = lead.State;
  LeadAccount.BillingStreet = lead.Street;
  LeadAccount.Website = lead.Website;
  LeadAccount.Website_Origin__c = lead.Website_Origin__c;
  // LeadAccount.Web_Source__c = lead.SFGA__Web_Source__c;
  LeadAccount.Work_Phone__pc = lead.Work_Phone__c;
  LeadAccount.BillingPostalCode = lead.PostalCode;
  insert LeadAccount;
  System.debug('LeadAccount = '+ LeadAccount);
  
 }
}
Colin LoretzColin Loretz
You are missing the person account record type. Try adding:
LeadAccount.isPersonAccount = true;

A query example would be:
Code:
QueryResult qr = query(“select Name, SobjectType,
         IsPersonType from RecordType where SobjectType=’Account’
         and IsPersonType=True”

 
More on Person Account Record types can be found here:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_guidelines_personaccounts.htm#topic-title
BoxBox
Once you enable person accounts you must use the record type to define what sort of account you are creating within APEX as you can no longer default as the person account has a slightly different data model behind it.

Your code should retrieve the ID of the record type you required from the RecordType table