I am writing test class where I need to create test data for standard case object object and parent object for a custom field in case object. When I do the test run it is giving error at the statement where Case object is associated to parent object
Case is linked to BuildingPermit1 with PermitName field. Please help.
private static Contact Contact1;
private static Case Case1;
private static Building_Permit__c BuildingPermit;
//create account
Account1 = new Account();
Account1.Name = 'Test Company';
insert Account1;
//create Contact
Contact1 = new Contact();
Contact1.FirstName = 'Testname';
Contact1.LastName = 'TLname';
Contact1.Phone = '6667897867';
Contact1.Email = '[email protected]';
//create building permit
Buildingpermit1 = new Building_permit__c();
Buildingpermit1.permit_name__c = 'testPermit’;
insert Buildingpermit1;
Case1 = new Case();
Case1.Origin = 'Phone';
Case1.Status = 'New';
Case1.ContactId = mainContact.Id;
Case1.Subject = 'test subject';
Case1.Description = 'test desc';
if (buildingpermit1.Id != null)
{
Case1.Buildingpermit1= Buildingpermit1.Id; //This is the statement where
//error shows up
}
Insert Case1;