1

I am currently updating contact related records on accounts which updates my contacts correctly. When i try this for account I get the error:

Method does not exist or incorrect signature: void addAll(Account) from the type List.

What is wrong with my signature. See below.

public PageReference updateContacts() {
system.debug('accList '+accList);

contactList = new List<Contact>();
for(Account accnt :accList){
    contactList.addAll(accnt.Contacts);
}

accountList = new List<account>();
for(Account accntnew :accList){
    accountList.addAll(accntnew);
}
update contactList;
update accList;
return null;
}

2 Answers 2

1

You don't need a loop to copy all the Accounts in the list, you can just use:

accountList = new List<account>();
accountList.addAll(accList);

or:

accountList = new List<account>(accList);

or:

accountList = accList.clone();

or not copy the list at all and just update using the original list.

1

The problem exists in below line of code

accountList.addAll(accntnew);

addAll() function expects list or set in the signature, while you are giving it a single Account object.

You should be using add() instead.

4
  • You didn't mention complete requirements in the question, since your question was only related to the problem / Error, that's why you got that suggested answer. Please post another question with complete requirements, where the reader would know about accList and other variables in place.
    – Mahmood
    Sep 5, 2017 at 13:44
  • This does not update the accountslist!?
    – Jenssen
    Sep 5, 2017 at 13:45
  • What error you are getting?
    – Mahmood
    Sep 5, 2017 at 13:46
  • with your solution the accounts do not get updated
    – Jenssen
    Sep 5, 2017 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .