0

whats wrong with this code? I am trying to loop through a list of contacts and for some reason it doesnt like the var con. I know its something very simple that i am missing, which makes me feel i shouldnt be working on a sunday

This is the SOQL i am using on the batch process to fetch the records

SELECT Id, name, (SELECT Id,accountid, Name,email FROM Contacts order by createddate asc) FROM Account

map<Id,List<contact>> mapContacts = new map<Id,List<contact>>();
for(sObject s : objectBatch)
        {
            Account a = (Account)s;
            mapContacts.put(a.id,a.contacts);
        }

for(Id accid : mapContacts.keyset())
        {
            List<contact>  contactList = new List<contact>();
            contactList = mapContacts.get(accid);
            system.debug(contactList);
            for(Contact con : contactList);
            {
                String key ='';
                contacts.clear();
                system.debug(con); //  Variable does not exist: con

            }

        }
6

Remove the semi-colon in the for loop statement; you have made the loop empty with a following block not related to it.

for (Contact con : contactList) {
    String key ='';
    contacts.clear();
    System.debug(con);
}
  • Phew!! Time to stop everything and have a cup of coffee. – Prady Mar 24 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.