Q:

Apex Syntax Error?

This code works in Execute Anonymous, but when I try to make an Apex class I get this error on line: Expecting '}' but was: 'insert'.  Any thoughts? Thanks.
public class InvoiceAccounts {
// Create a list of InvoiceAccounts
List<InvoiceAccount__c> InvA_List = new List<InvoiceAccount__c> {
 new InvoiceAccount__c(Name='Joe',Account_Owner_Name__c='Smith',Account_Owner_Title__c='Sir'),
new InvoiceAccount__c(Name='Kathy',Account_Owner_Name__c='Smith',Account_Owner_Title__c='Sir'),
new InvoiceAccount__c(Name='Caroline',Account_Owner_Name__c='Roth',Account_Owner_Title__c='Sir'),
 new InvoiceAccount__c(Name='Kim',Account_Owner_Name__c='Shain',Account_Owner_Title__c='Sir')};

// Bulk insert all InvoiceAccount__cs with one DML call

insert InvA_List;

}

A:

Within a class, executable code must be inside of a method. Typically, this means you simply add a line for the method signature, and another closing curly bracket.
public class InvoiceAccounts {
  public static void createInvoiceAccounts() {
    // Create a list of InvoiceAccounts
    List<InvoiceAccount__c> InvA_List = new List<InvoiceAccount__c> {
      new InvoiceAccount__c(Name='Joe',Account_Owner_Name__c='Smith',Account_Owner_Title__c='Sir'),
      new InvoiceAccount__c(Name='Kathy',Account_Owner_Name__c='Smith',Account_Owner_Title__c='Sir'),
      new InvoiceAccount__c(Name='Caroline',Account_Owner_Name__c='Roth',Account_Owner_Title__c='Sir'),
      new InvoiceAccount__c(Name='Kim',Account_Owner_Name__c='Shain',Account_Owner_Title__c='Sir')};

    // Bulk insert all InvoiceAccount__cs with one DML call

    insert InvA_List;

  }
}

Which you then call as a static method:
InvoiceAccounts.createInvoiceAccounts();

