I'm trying to modify my code which works for single account, but I need to handle multiple accounts.
split[0] : holds the account name
split[1] : holds the email
This is my code:
list<string> slistAcc = new list<string>{'[email protected]','[email protected]'};
system.debug(slistAcc);
list<account> acct = new list<account>();
list<account> p2 = new list<account>();
string[] b;
for(integer i=0;i<slistAcc.size();i++)
{
string a = slistAcc[i];
b = a.split('_');
system.debug('b --->' + b); << ---DEBUG|b --->(abc, [email protected])
if(!b.IsEmpty())
{
acct[i].name = b[0]; <<---keeps failing in this assignment.
acct[i].email = b[1];
system.debug('acct' + acct[i]);
p2.add(acct[i]) <---------
}
}
insert p2;
The code keeps failing at the assignment to **acct[i].name = b[0]**
saying List index out of bounds...
. I don't get how can I assign multiple accounts to a variable. or a list to a list [b is also a list and acct is also a list]. What am trying to achieve is from the split list get account name and email assign to new list -- this needs to be looped through several data in that split array. Now capture all these new assigned values and insert in system using p2.
Please advise. Also please excuse me as I'm still getting used to Apex.