function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BearDog515BearDog515 

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 Na​me = '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 'Na​me' 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.

 

Best Answer chosen by Admin (Salesforce Developers) 
LegendLegend

Hi,

 

If it is a person account then use FirstName and LastName instead of Name while inserting an Account.

All Answers

LegendLegend

Hi,

 

If it is a person account then use FirstName and LastName instead of Name while inserting an Account.

This was selected as the best answer
BearDog515BearDog515

It doesn't make sense that I would get THAT error message for this reason, but it nevertheless works!  Thanks for the assist!

LegendLegend

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.