function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mr SreeniviasMr 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 
Shiva RajendranShiva Rajendran
hi Sreenivas,
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
Surendra Choudhary 1Surendra Choudhary 1
Hi Sreenivas,

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;
 
Surendra Choudhary 1Surendra Choudhary 1

Hi Sreenivas,

This above code will definitly run. For more queries you can contact me as well on skype : surendra.choudhary12

Regards,

Surendra

Surendra Choudhary 1Surendra Choudhary 1
Hi Sreenivas,

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
Mr SreeniviasMr Sreenivias
 thanks ,siva.... it working.  and @surandra also thanks ur intrest on my question.........