I have a simple Apex trigger I'm trying to write a test for, but I get the error in the title when trying to save (error is at line 15 'insert n;'). I don't get this error in the line that inserts the lead. I've tried new Note() instead of passing through Note attributes and inserting the Note the same way I do the Lead, but nothing has worked so far, I feel like I'm overlooking a small syntax issue somewhere:
@isTest
public class TestNoteOnInsert {
private static Id leadId;
static {
Lead testLead = new Lead();
testLead.FirstName = 'Test first';
testLead.LastName = 'Test last';
testLead.Status = 'Open';
testLead.Company = '100 test lane Brooklyn, NY';
insert testLead;
leadId = testLead.Id;
}
Note n = new Note(title='Sales Rabbit Note', body='Test', ParentId=leadId);
Test.startTest();
insert n;
Test.stopTest();
system.assertEquals(testLead.Notes__c, 'Test');
}