1

I am having trouble creating this map, c2g__codaCompany__c name should be the key and ID of Journal_Staging__c should be the value.. please help? I currently have the following error:

Loop variable must be a generic SObject or List or a concrete SObject or List of: c2g__codaCompany__c

List<Journal_Staging__c> journals = new List<Journal_Staging__c>();
// map to get all companies
Map<Id, c2g__codaCompany__c> companies = New Map<Id, c2g__codaCompany__c>([Select Id, Name FROM c2g__codaCompany__c]);

// for each company, create a journal, setting that company id on the journal - pass this to list and make public 
for(c2g__codaCompany__c c : companies.keySet()) {
    journals.add(new Journal_Staging__c(
    // set company lookup - no name - auto generated - only put id not name, using get got the whole record. 
    Company__c = c.Id));
}

// insert journals to get id for jlis
insert journals;

// map of company name to journal id
List<Journal_Staging__c> getNewJournals = [Select Id, Name, Company__c FROM Journal_Staging__c];
Map<String, Id> companyJournal = New Map<String, Id>();

for(Journal_Staging__c j : [SELECT Name FROM c2g__codaCompany__c]) {
    companyJournal.put(j.Name, j.Id);
}
4

You have a syntax error in the line:

for(c2g__codaCompany__c c : companies.keySet()) {

Your keySet has type Set<Id>, but your for loop is expecting a c2g__codaCompany__c. Change the line to

for(c2g__codaCompany__c c : companies.values()) {

to iterate over the set of c2g__codaCompany__c contained in the map.

Please see the Map class documentation for more details.

| improve this answer | |

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.