You need to sign in to do that
Don't have an account?
Mr Sreenivias
Line: 9, Column: 21 Initial term of field expression must be a concrete SObject: List<Account> error
list<account> acc= [select id from account where name='wipro' ];
list<contact> cons= new list<contact>();
for(list<account> a : acc)
{
contact con = new contact();
con.firstname='schnider';
con.lastname='electrics';
con.AccountId=acc.Id;
cons.add(con);
}
insert cons;
how to solve it
list<contact> cons= new list<contact>();
for(list<account> a : acc)
{
contact con = new contact();
con.firstname='schnider';
con.lastname='electrics';
con.AccountId=acc.Id;
cons.add(con);
}
insert cons;
how to solve it
This error generally occurs when you accessed list as normal variable.
You have used acc.id ,acc is a list of accounts not a account . You should use
con.AccountId = a.Id not acc.Id.
Now the code will work
Thanks and Regards,
Shiva RV
Use below code:
list<account> acc= [select id from account where name='wipro' ];
list<contact> cons= new list<contact>();
for(Account a : acc)
{
contact con = new contact();
con.firstname='schnider';
con.lastname='electrics';
con.AccountId=acc.Id;
cons.add(con);
}
insert cons;
Hi Sreenivas,
This above code will definitly run. For more queries you can contact me as well on skype : surendra.choudhary12
Regards,
Surendra
Sorry, please use this code and make changes as highlighted in bold.
list<account> acc= [select id from account where name='wipro' ];
list<contact> cons= new list<contact>();
for(Account a : acc)
{
contact con = new contact();
con.firstname='schnider';
con.lastname='electrics';
con.AccountId=a.Id;
cons.add(con);
}
insert cons;
Regards,
Surendra