Skip to main content

Set<ID> existingPersonIds = new Set<Id>();

for(FFA_Child_Functioning__c existingCFObj :[select id, Person_Cases__r.Person__c from FFA_Child_Functioning__c where FFA_Case_Information__c =:ffaCaseInfoId ]){

       existingPersonIds.add(existingCFObj.Person_Cases__r.Person__c);

}

for(FFA_Adult_Functioning__c existingAFObj :[select id, Person_Cases__r.Person__c from FFA_Child_Functioning__c where FFA_Case_Information__c =:ffaCaseInfoId ]){

          existingPersonIds.add(existingAFObj.Person_Cases__r.Person__c);

}

force-app\main\default\classes\FLCW_FFAOAddParticipantsController.cls  Loop variable must be a generic SObject or List or a concrete SObject or List of: FFA_Child_Functioning__c (36:17)

 

Trying to add the same object id's in the Set so that I can use this set make another query on another object. But getting an error on second loop. 

Kindly help

 

@* Salesforce Developers * 

2 answers
  1. Oct 14, 2024, 3:48 PM

    Hi @Sanjeev Kumar

     

    In the second loop, Correct the object type to FFA_Adult_Functioning__c, it should be same in both the loop variable and the SOQL query. This ensures that you are iterating over the correct type of records. Hope this helps!!

     

    // Loop through FFA_Child_Functioning__c records

    for (FFA_Child_Functioning__c existingCFObj : [SELECT Id, Person_Cases__r.Person__c FROM FFA_Child_Functioning__c WHERE FFA_Case_Information__c = :ffaCaseInfoId]) {

        existingPersonIds.add(existingCFObj.Person_Cases__r.Person__c);

    }

     

    // Loop through FFA_Adult_Functioning__c records

    for (FFA_Adult_Functioning__c existingAFObj : [SELECT Id, Person_Cases__r.Person__c FROM FFA_Adult_Functioning__c WHERE FFA_Case_Information__c = :ffaCaseInfoId]) {

        existingPersonIds.add(existingAFObj.Person_Cases__r.Person__c);

    }

0/9000