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
prasad1.3969574005596787E12prasad1.3969574005596787E12 

Initial term of field expression must be a concrete SObject: LIST

I am trying to update an account from contact field as i had tried my code having this error
"Initial term of field expression must be a concrete SObject: LIST"

List<Account> acc = new List<Account>();
List<Contact> con = new List<Contact>();
Set<Id> setid = new Set<Id>();

Contact c = new contact();
Account a = new Account();

con = [SELECT name,Accountid FROM Contact WHERE Lastname='Rahul'];
setid.add(con.id);
acc = [SELECT name FROM Account WHERE id in: setid];
acc.name = 'Naveen Rahul';
update acc;


Best Answer chosen by prasad1.3969574005596787E12
Ramu_SFDCRamu_SFDC
Hi,

acc is a list of accounts but you are trying to set the list variable name as if it is an individual record.

Try doing 

acc[0].name = 'Naveen Rahul';

or use a for loop to loop through the account results and declare each account name as 'Naveen Rahul'

Hope this helps !!

All Answers

Ramu_SFDCRamu_SFDC
Hi,

acc is a list of accounts but you are trying to set the list variable name as if it is an individual record.

Try doing 

acc[0].name = 'Naveen Rahul';

or use a for loop to loop through the account results and declare each account name as 'Naveen Rahul'

Hope this helps !!
This was selected as the best answer
prasad1.3969574005596787E12prasad1.3969574005596787E12
con = [SELECT accountid FROM Contact WHERE Lastname='Rahul'];
setid.add(con.id);
for(integer i=0; i<10; i++)
	acc = [SELECT id,name FROM Account where id in: setid[i]];
acc.name = 'Naveen Rahul';
same error
Ramu_SFDCRamu_SFDC
con = [SELECT accountid FROM Contact WHERE Lastname='Rahul'];
setid.add(con.id);

acc = [SELECT id,name FROM Account where id in: setid];

for(integer i=0; i<setid.size(); i++){
acc[i].name = 'Naveen Rahul';
}

update acc;


Note : Never use SOQL statements within for loop. Let me know if you have any further issues.
prasad1.3969574005596787E12prasad1.3969574005596787E12

Thankyou,

I got the solution.......!

List<Account> acc = new List<Account>();
//List<Contact> con = new List<Contact>();
Set<Id> sid = new Set<Id>();

for(Contact con : [SELECT Name, AccountId FROM Contact WHERE LastName = 'Rahul'])
{
    sid.add(con.AccountId);
}
acc = [SELECT  Name FROM Account WHERE Id IN :sid];
for(Account a : acc)
{
    a.Name = 'Prasad';
}
UPDATE acc;

ThankQ for  all.....

:-)