You need to sign in to do that
Don't have an account?
Problem inserting person account in test method.
Hello
I've searched the boards for an answer to this and couldn't find one. I'm new to apex and programming in general so apologies if this is very basic...
I have the following test method in an apex class:
public static testMethod void dateSetTest(){ Lead prospect = new Lead(LastName = 'Test'); Database.insert(prospect); Account acct = new Account(Name = 'Test'); acct.recordTypeId = [SELECT Id FROM RecordType WHERE Name = 'Person Accounts'].Id; Database.insert(acct); Case c = new Case(AccountId = acct.Id, Subject = 'Test', Origin = 'Inbound Call', Reason = 'Customer Inquiries', Primary_Type__c = 'Test', Primary_Subtype__c = 'Test', Survey_Email_Sent__c = false); Database.insert(c); c.Survey_Email_Sent__c = true; Database.update(c); Account acctToCheck = [SELECT Id, Last_Survey_Sent__c FROM Account WHERE Id = :acct.Id]; System.assert(acctToCheck.Last_Survey_Sent__c != null); }
I'm getting the following error which makes no sense at all:
Error: Compile Error: No such column 'Name' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
I am authoring this from a System Administrator profile so I don't believe it's a FLS issue. Any thoughts or help would be appreciated.
Hi,
If it is a person account then use FirstName and LastName instead of Name while inserting an Account.
All Answers
Hi,
If it is a person account then use FirstName and LastName instead of Name while inserting an Account.
It doesn't make sense that I would get THAT error message for this reason, but it nevertheless works! Thanks for the assist!
Hi,
Actually there is a slight difference between Business Account and Person Account. If you are dealing with Person Account then you have to use FirstName and LastName. Its OOB functionality.