Skip to main content
Lisa Schutter 님이 #Apex에 질문했습니다
Hi All, Hope someone can help me. After the sandbox refresh I am running a script to update accounts. It works for all my objects, but Person Accounts. Does anyone have any Idea how to fix it? 

This is the error that is shown in the last line of my debug:

 

EXCEPTION_THROWN|[47]|System.DmlException: Insert failed. First exception on row 2; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, entity type cannot be inserted: Person Account: []

This is my apex class:

 

global class sandboxRefreshScript implements SandboxPostCopy{

global void runApexClass(SandboxContext context)

{

List<Account> accounts = new List<Account>();

Account a1 = new Account();

a1.Name = 'J&T Autolease';

a1.Ownerid = '005w0000005bvNR';

a1.Type = 'LeaseCo';

a1.Status__c = 'Partner';

a1.Phone = '013 820 07 00';

a1.BillingStreet = 'Kraaivenstraat 4';

a1.BillingCity = 'Tilburg';

a1.BillingPostalCode = '5048 AB';

a1.BillingState = 'Zuid-Holland';

a1.ShippingStreet = 'Kraaivenstraat 4';

a1.ShippingCity = 'Tilburg';

a1.ShippingPostalCode = '5048 AB';

a1.ShippingState = 'Zuid-Holland';

accounts.add(a1);

Account a2 = new Account();

a2.Name = 'Adler';

a2.Ownerid = '005w0000006WaIF';

a2.BillingCountry = 'Netherlands';

a2.ShippingCountry = 'Germany';

accounts.add(a2);

Account a3 = new Account();

a3.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Person Account').getRecordTypeId();

a3.Status__c = 'Customer';

a3.OwnerId = '005w0000004Sz1E';

a3.Salutation = 'Mr.';

a3.FirstName = 'Trafineo';

a3.LastName = 'Trafineo';

a3.PersonEmail = 'settlement+trafineo@thenewmotion.com';

a3.PersonMailingCity = 'Bochum';

a3.PersonMailingStreet = 'Wittener Straße 56';

a3.PersonMailingPostalCode = '44789';

a3.PersonMailingCountry = 'Germany';

a3.hidden_email__c = 'settlement+trafineo@thenewmotion.com';

accounts.add(a3);

insert Accounts;

List<Contact> contacts = new List<Contact>();

Contact b1 = new Contact();

b1.Salutation = 'Mr.';

b1.FirstName = 'Arjen';

b1.LastName = 'Butter';

b1.Email = 'c.leusink@newmotion.com';

b1.Accountid = a1.ID;

contacts.add(b1);

insert Contacts;

List<Opportunity> opportunities = new List<Opportunity>();

Opportunity c1 = new Opportunity();

c1.Name = 'Zonnestraal';

c1.Ownerid = '005w0000005bvM4';

c1.StageName = 'Intake';

c1.Accountid = a1.ID;

opportunities.add(c1);

insert Opportunities;

List<Payment_Account__c> paymentaccounts = new List<Payment_Account__c>();

Payment_Account__c d1 = new Payment_Account__c();

d1.Name = 'J&T Autolease*';

d1.Ownerid = '005w0000005bvM4';

d1.Billing_Name__c = 'Financiele administratie';

d1.Billing_Email__c = 'l.schutter@newmotion.com';

d1.Payment_Terms__c = '30';

d1.Billing_Address__c = 'Postbus 2094';

d1.Billing_PostalCode__c = '5001 CB';

d1.Billing_City__c = 'Tilburg';

d1.Billing_Country__c = 'NL';

d1.Account__c = a1.Id;

paymentaccounts.add(d1);

insert paymentaccounts;

}

}

 
답변 16개
  1. 2017년 7월 31일 오후 9:24
    Hi Alain, where can I find the record type settings? 

    This is our Account trigger:

     

    trigger AccountTrigger on Account (after delete, after insert, after undelete,

    after update, before delete, before insert, before update) {

    System.debug('+++trigger.isBefore: '+trigger.isBefore);

    System.debug('+++trigger.isInsert: '+trigger.isInsert);

    System.debug('+++trigger.isUpdate: '+trigger.isUpdate);

    AccountUtil.entry(new TriggerParams(trigger.isBefore, trigger.isAfter, trigger.isInsert, trigger.isUpdate, trigger.isDelete,

    trigger.isUndelete, trigger.new, trigger.old, trigger.newMap, trigger.oldMap));

    }

     
0/9000