I was writing a test class to pass data into my controller. I received the following error:
Error: Compile Error: Invalid field AccountId for SObject Account at
line 8 column 9
Test Class
@isTest
private class AccountContactControllerTest{
static testMethod void myUnitTest1() {
Account a = new Account();
a.Name = 'Project Account Test';
**a.Parent = 'Parent Account';**
a.Account_Email__c = 'anyuser@gmail.com';
a.Site = 'www.google.com';
a.Customer_ID__c = '1002';
a.Project_Id__c = '1221.0001';
insert a;
Contact c = new Contact();
c.FirstName = 'Test first name';
c.LastName = 'Test last name';
c.Email = 'contactemail@gmail.com';
c.Phone = '5546747737';
insert c;
sm1e__smEquipment__c assetTag = new sm1e__smEquipment__c();
assetTag.Purchase_Date__c = date.newInstance(2016, 6, 1);
assetTag.Name = '1021.0001 - Plant';
assetTag.Plant_Business_Segment__c = 'EV';
assetTag.Business_Segment__c = 'EV';
assetTag.Operator__c = 'CalCom';
assetTag.sm1e__Service_Region__c = 'Central';
insert assetTag;
}
}
How do I pass test Data into the parent account field?
Best Answer
You have to create parent Account first, then use the id of the Parent at the child.
Sample code looks like: