Blog

Main » 2018 » December » 11

split a single account into individual contacts

list tweContact = new list([Select Id, FirstName, LastName, AccountID from Contact where AccountID = '001E000001cxEiGIAU' LIMIT 10]);
system.debug(tweContact.size());
list newAccounts = new list();
for (Contact c: tweContact ) {
 Account a = new Account(Name=c.FirstName+ ' '+c.LastName);
 insert a;
 c.AccountID = :a.Id;
 update c;
}