Hello I am currently working on a side project to practice SOQL Query. My task was to Write a class to insert 3 contacts with account Id = Id of Dickenson Plc. I have spend hours looking over my code and I don't know what I am doing wrong. The code runs but when I go in my salesforce no contacts have been inserted. Can someone please help me? Also as stated before i had to query the account id that I wanted which was account that is already in salesforce but the contacts accountid should all be related to the same id.
Hi @Alexis Williams ,
Try this
Public class ContactInsertion {
public static void insert Contact(){
List<Contact> addContact = new List<Contact>();
Integer i =1;
List<Account> accList =[select Id From Account where Name ='Dickenson plic'];
for (i=1;i<=3;i++){
Contact newCon = new Contact();
newCon.FirstName = 'Lisa' + i;
newCon.LastName = 'Doe' + i;
newCon.AccountId = accList[0].Id;
addContact.add(newCon);
}
insert addContact;
}
}