function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
arsars 

Binding Apex Repeat (up to Five Levels)

APEX CLASSES

 

public List<cCampaign> getcCampaign(){       

    Campaign[] campParent = [Select Id, Name from Campaign where id = :c.Id];       

   

        ParentCmembers =  [Select Contact.Id from CampaignMember where Campaignid = :campParent[0].id];              

        for (CampaignMember cm : ParentCmembers){

            ParentMemberIds.add(cm.Contact.Id);

        }

 

        cCampaign x = new cCampaign(campParent[0],ParentMemberIds);

        lCampaign.add(x);                    

       

       

        CmParent.add(campParent[0].Id);

        CmParentName.add(campParent[0].Name);

        TotalCampaignIds.add(campParent[0].Id);

       

        return lCampaign;   

}

 

public List<cCampaign> getChildcampaign(){

 

    Campaign[] campChild = [Select Id ,Name from Campaign where Parent_Campaign_Name__c like: CmParentName];

 

    if (campChild .size() > 0){

           

        for (integer i = 0; i < campChild.size();i++){

            sCampaignIds.add(campChild[i].Id);

            TotalCampaignIds.add(campChild[i].Id);

            sCmChildlv3.add(campChild[i].Name);

        }

           

        ChildCmembers  =  [Select Id,Contact.Id,Campaignid from CampaignMember where Campaignid in :sCampaignIds];              

       

        for (integer i = 0; i < ChildCmembers.size();i++){

              sContactid.add(ChildCmembers[i].Contact.Id);

        }

        

        for (integer i = 0; i < campChild.size();i++){

            cCampaign childCampaign = new cCampaign(campChild[i],sContactid);

            lChildCampaign.add(childCampaign);     

        }           

       

        return lChildCampaign;

    }

    else{

        return null;

    }   

}

 

public List<cCampaign> getChildLvl3(){

 

    Campaign[] campChild3 = [Select Id ,Name from Campaign where Parent_Campaign_Name__c In: sCmChildlv3];

    sCampaignIds.clear();

    if (campChild3.size() > 0){

           

        for (integer i = 0; i < campChild3.size();i++){

            sCampaignIds.add(campChild3[i].Id);

            TotalCampaignIds.add(campChild3[i].Id);

            sCmChildlv4.add(campChild3[i].Name);

        }

           

        ChildCmembers  =  [Select Id,Contact.Id,Campaignid from CampaignMember where Campaignid in :sCampaignIds];              

       

        for (integer i = 0; i < ChildCmembers.size();i++){

              sContactid.add(ChildCmembers[i].Contact.Id);

        }

        for (integer i = 0; i < campChild3.size();i++){

            cCampaign childCampaign = new cCampaign(campChild3[i],sContactid);

            lChildCampaign3.add(childCampaign);     

        }           

       

        return lChildCampaign3;

    }

    else{

        return null;

    }   

}

 

=============================================================================

PAGES 

 

        <apex:repeat value="{!cCampaign}" var="ch" rendered="{!NOT(ISNULL(cCampaign))}">

            <tr>       

                <td colspan="5" HeaderValue="Campaign Name" style="width:40%">

                    <apex:outputLink title="" value="/{!ch.Cmp.Id}">

                    <apex:outputText value="{!ch.Cmp.Name}"/>

                    </apex:outputLink>

                </td>

                <td style="width:15%">{!ch.fedCount}</td>

                <td style="width:15%">{!ch.fedResponse}</td>

                <td style="width:15%">{!ch.NonfedCount}</td>

                <td style="width:15%">{!ch.NonfedResponse}</td>                                                                

            </tr>      

           

            <apex:repeat value="{!ChildCampaign}" var="c2" rendered="{!NOT(ISNULL(cCampaign))}" >

                <tr>

                    <td width="25px"></td>

                    <td colspan="4" style="width:40%">

                        <apex:outputLink title="" value="/{!c2.Cmp.Id}">

                        <apex:outputText value="{!c2.Cmp.Name}"/>

                        </apex:outputLink>

                    </td>

                    <td style="width:15%">{!c2.fedCount}</td>

                    <td style="width:15%">{!c2.fedResponse}</td>

                    <td style="width:15%">{!c2.NonfedCount}</td>

                    <td style="width:15%">{!c2.NonfedResponse}</td>                                                                 

                </tr>          

               

                <apex:repeat value="{!ChildLvl3}" var="c3" rendered="{!NOT(ISNULL(cCampaign))}" >

                    <tr>

                        <td width="25px"></td>

                        <td width="25px"></td>       

                        <td colspan="3" style="width:40%">

                            <apex:outputLink title="" value="/{!c3.Cmp.Id}">

                            <apex:outputText value="{!c3.Cmp.Name}"/>

                            </apex:outputLink>

                        </td>

                        <td style="width:15%">{!c3.fedCount}</td>

                        <td style="width:15%">{!c3.fedResponse}</td>

                        <td style="width:15%">{!c3.NonfedCount}</td>

                        <td style="width:15%">{!c3.NonfedResponse}</td>

                    </tr>

                </apex:repeat>

            </apex:repeat>

        </apex:repeat>

 

 

================================================

Question:

We are creating the Custom Campaign Hierarchy...

Based from the CLASS created, how can we bind the repeat value up to Five (5) levels in the hierarchy?
 
Sample (something like this)...

Campaign Itself

                Child 1 Campaign

                                Child Child Campaign

                                                Child Child Child Campaign

                                                                Child Child Child Child Campaign

                Child 2 Campaign

 
 
This is getting me crazy :( and Thanks in advance ^_^
bob_buzzardbob_buzzard

If you want to nest in that way, each instance of ccampaign will have to maintain a list of ccampaign class instances and so on.  Then each nested repeat would iterate that list.

arsars

Sorry, but what do you mean... maintain a list of ccampaign intances?

 

This is our actual result:

Campaign

                Child 1 Campaign

                                Child Child 1 Campaign

                                Child Child 2 Campaign

                Child 2 Campaign

                                Child Child 1 Campaign

                                Child Child 2 Campaign

 

...when is should be:

Campaign

                Child 1 Campaign

                                Child Child 1 Campaign

                                Child Child 2 Campaign

                Child 2 Campaign

 

 

 

bob_buzzardbob_buzzard

The problem here is that you have one list of child campaigns, so this will be iterated for each parent campaign.  Then you have one list of grandchildren and this will be iterated each time through.

 

You need to structure your data to match the output you want - each sub-level of campaign is stored inside its parent.