You need to sign in to do that
Don't have an account?
Markus Pallo
How to create personaccounts in apex test classes
Hello,
i need to test a class which needs account.isPersonAccount set.
My test fails, because i am not able to initialize the property inside the test method.
My test method:
@IsTest
public static void testPersonAccountFields() {
Schema.RecordTypeInfo recordTypeInfo = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosByDeveloperName().get('PersonAccount');
System.assert(recordTypeInfo != null, 'There must be a Person Account record type');
String recordTypeId = recordTypeInfo.getRecordTypeId();
Account account = new Account(RecordTypeId = recordTypeId);
account.FirstName = 'First';
account.LastName = 'Last';
System.assert(account.isPersonAccount, 'must be a person account');
// here call code which needs is PersonAccount set
}
any help appreciated.
Markus
i need to test a class which needs account.isPersonAccount set.
My test fails, because i am not able to initialize the property inside the test method.
My test method:
@IsTest
public static void testPersonAccountFields() {
Schema.RecordTypeInfo recordTypeInfo = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosByDeveloperName().get('PersonAccount');
System.assert(recordTypeInfo != null, 'There must be a Person Account record type');
String recordTypeId = recordTypeInfo.getRecordTypeId();
Account account = new Account(RecordTypeId = recordTypeId);
account.FirstName = 'First';
account.LastName = 'Last';
System.assert(account.isPersonAccount, 'must be a person account');
// here call code which needs is PersonAccount set
}
any help appreciated.
Markus
(Please mark this as best answer if it resolves your issue)
All Answers
(Please mark this as best answer if it resolves your issue)
thanks Kritia Raj
i have to requery than it will work, i changed to
Markus