First option is to query the RecordType object as follows:
List<RecordType> rType = [Select Id, Name From RecordType Where name = 'Person Account'
and sobjectType = 'Account'];
and sobjectType = 'Account'];
This is pretty straightforward. However, if your client decides to customize the Name for the record type (i.e. Person Accounts 2), the above query is not longer flexible.
Second option is to query the RecordType object using the IsPersonType field as follows:
List<RecordType> rType = [Select Id, Name, sobjectType, IsPersonType From RecordType
Where IsPersonType = true and sobjectType = 'Account'];
Finally, you will need to create the Person Account as follows:
Account acct = new Account(); acct.RecordTypeId = rType .get(0).Id; acct.LastName = 'Test'; |
No comments:
Post a Comment