You need to sign in to do that
Don't have an account?
Thomas Fuller
Apex/Visualforce: How do you modify a collection before it is iterated into a VF page?
Hey everybody,
I am currently working on a Visualforce component where it will display a filtered related list on the main page layout of the "Projects" ("PE_Projects__c") custom object. I've looked up various sources on how to achieve a filtered related list, and I've created a rough bit of code to test. However, everytime I load a Projects page, an error message appears in the Visualforce window saying: "Content cannot be displayed: Cannot modify a collection while it is being iterated." After researching this error a bit, I've tried using the addAll() method to copy a finished list to the "projConList" list. However, I'm still back at square one.
Visualforce Code:
Apex Code:
I was hoping some experienced VF developers would mind helping a newbie out by providing any suggestions, ideas, solutions, etc.
Thanks so much for your time.
I am currently working on a Visualforce component where it will display a filtered related list on the main page layout of the "Projects" ("PE_Projects__c") custom object. I've looked up various sources on how to achieve a filtered related list, and I've created a rough bit of code to test. However, everytime I load a Projects page, an error message appears in the Visualforce window saying: "Content cannot be displayed: Cannot modify a collection while it is being iterated." After researching this error a bit, I've tried using the addAll() method to copy a finished list to the "projConList" list. However, I'm still back at square one.
Visualforce Code:
<apex:page standardController="PE_Projects__c" extensions="ProjectRolesMainClass"> <apex:form> <apex:pageBlock > <apex:pageBlockTable value="{!projConList}" var="p"> <apex:column value="{!p.Name}"/> <apex:column value="{!p.Project_Contacts_con__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Apex Code:
public class ProjectRolesMainClass { public List<Project_Contacts__c> projConList{get;set;} public ProjectRolesMainClass(ApexPages.StandardController controller) { List<Project_Contacts__c> tempList=[select Id, Project_Contacts_con__c from Project_Contacts__c where Project_Contacts_proj__c=:ApexPages.currentPage().getParameters().get('id')]; for(Project_Contacts__c PR:tempList) { tempList.add(PR); } projConList.addAll(tempList); } }
I was hoping some experienced VF developers would mind helping a newbie out by providing any suggestions, ideas, solutions, etc.
Thanks so much for your time.
projConList = [select Id, Name, Project_Contacts_con__c from Project_Contacts__c where Project_Contacts_proj__c = :ApexPages.currentPage().getParameters().get('id')] ;
that should be the only line you need in the constructor method.
All Answers
projConList = [select Id, Name, Project_Contacts_con__c from Project_Contacts__c where Project_Contacts_proj__c = :ApexPages.currentPage().getParameters().get('id')] ;
that should be the only line you need in the constructor method.