+ Start a Discussion
Patrick Mayer 4Patrick Mayer 4 

Creating and Using a Person Account

Account acct = new Account(RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Person Account').getRecordTypeId());
        acct.Phone = o.Customers_Phone__c;
        acct.PersonEmail = o.Customers_Email__c; 
        acct.FirstName = o.Customers_First_Name__c;
        acct.LastName = o.Customers_Last_Name__c;
        acct.Customer_Id__c = o.EatStreet_Customer_ID__c.toPlainString();
        insert acct;
        system.debug(acct.IsPersonAccount);
        temp.Customer__c = acct.PersonContactId;

Here is a relevant code snippet. I am most concerned with why the system.debug line returns false. Any insights would be great.
bob_buzzardbob_buzzard
Do you get a record type id set into the account? And is the record type named"'Person Account" definitely setup as a person record type?

When I've pulled the record type for a person account I've used the following code - its more low level but guarantees the record type returned is for a person account (it will also fail if it doesn't get a record type id matching the name, which might not be what you want) : 

RecordType personaccountRecordType = [SELECT Id, Name, SobjectType, IsPersonType
                                              FROM RecordType
                                              WHERE SobjectType = 'Account'
                                              AND IsPersonType = True
                                              AND Name = 'Person Account'];