+ Start a Discussion
surya yeturusurya yeturu 

Inserting records using List a simple programm. But i am getting errors ,can anyone help please.

public class Test
{
List<Contact> acctList = new List<Contact>(); 
Contact a1 = new Contact(FirstName='Account1'LastName='sri'); 
Contact a2 = new Contact(FirstName='Account2' LastName='sri'); 
acctList.add(a1);
acctList.add(a2);
insert acctList;
}
ANUTEJANUTEJ (Salesforce Developers) 
Hi Surya,

Can you try checking the below code once:
 
public class Test
{
    public static void method1(){
List<Contact> acctList = new List<Contact>(); 
Contact a1 = new Contact(FirstName='Account1',LastName='sri'); 
Contact a2 = new Contact(FirstName='Account2', LastName='sri'); 
acctList.add(a1);
acctList.add(a2);
insert acctList;
        system.debug(acctlist);
}}

Execute Test.method1(); from the anonymous window.

I hope this helps and in case if this comes handy can you please choose this as the best answer so that it can be useful for others in the future.

Regards,
Anutej
GulshanRajGulshanRaj
Contact a1 = new Contact(FirstName='Account1', LastName='sri'); 
Contact a2 = new Contact(FirstName='Account2' , LastName='sri');
You are missing  ","
 
Mayur Gore 10Mayur Gore 10
1. You are missing Method
2.Comma between FirstName and LastName