Why do i get this error:
System.NullPointerException: Attempt to de-reference a null object
My testclass looks like:
@isTest
public class attachPDFTestClass {
static Account testAccount;
static {
testAccount = new Account();
testAccount.Name = 'REALIANCE';
insert testAccount;
}
static testMethod void testAttachments() {
system.debug('line 2');
//system.debug('id Testaccount: '+testAccount.id);
system.debug(testAccount.Id);
Facturatie__c testFactuur = new Facturatie__c();
system.debug('line 3');
system.debug(testAccount.Name);
testFactuur.Accountname__r.Name = testAccount.Name;
system.debug('line 4');
insert testFactuur;
system.debug('id testFactuur: '+testFactuur.id);
system.debug(testAccount.Name); is ok
@isTest public class attachPDFTestClass { static testMethod void testAttachments() { Account testAccount = new Account(); testAccount.Name = 'REALIANCE'; insert testAccount; system.debug(testAccount.Id); Facturatie__c currentRecord = new Facturatie__c(); currentRecord.Accountname__r.Name = testAccount.Name; system.debug('testAccount debug'+ testAccount.Name); insert currentRecord;