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
Saniya Khan 2Saniya Khan 2 

more than 1000 records

Hi All,
I got an requirement in which want to display campaign member and its partner status of perticuler event in one vf page.
and each event have 1000's of campaign member and want to display campaign member details and its partner details.
I am using wrapper class for this so I can combine the campaign member details and its partner details in one page .
but in for loap when I try to retrieve partner details from its throwing an  error of so many query.

How to deal with this?
Any help will be appreciated.
Many thanks,
Saniya

 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Saniya,

Greetings to you!

You can use SOQL For Loops to overcome this problem.

So if your regular query is as below:
List<Account> accounts = new List<Account>();
accounts = [SELECT Id, Name FROM Account];

Then instead of the above query, you can use:
List<Account> accounts = new List<Account>();

for(Account acc : [SELECT Id, Name FROM Account]) {
accounts.add(acc);
}

However, note that this can work up to 50,000 records.

Please refer to below link for more information:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_loops_for_SOQL.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Saniya Khan 2Saniya Khan 2
Hi Anas,
Thanks for your reply.
I tried with the way which you told me but it still showing same error 101 so many query

here is my code  if you can have a look it will be great.
public class CampaignReport2Handler {
    public campaign c;
    List<CampaignMember> Campmembers {get; set;}
    public String pickvalue {get; set;}
    public String PartnerName1;
    Public String PartnerStatus1;
    public integer total_size;
    public Integer acceptedtot {get; set;}
    public Integer othercount {get; set;}
    public SET<id> principalID=new Set<id>();
    Map<id,CampaignMember> cmmap=new Map<id,CampaignMember>();
    public List<wrapperclass> wrapperCampList=new List<wrapperclass>();
    
     public CampaignReport2Handler(ApexPages.StandardController stdController)
    {
        this.c = (campaign)stdController.getRecord();
         total_size=[select count() From CampaignMember where CampaignId=:this.c.Id and Access_Level__c='Full' and Status__c IN ('Invited','Accepted','Declined','Cancelled') ];
         acceptedtot=[select count() From CampaignMember where CampaignId=:this.c.Id and Access_Level__c='Full' and Status__c='Accepted'];
        othercount=total_size-acceptedtot;
    }
public List<wrapperclass> getWrapperList()
    {
          for(CampaignMember camp:[select id,Post_Category__c ,Full_Name_including_Salutation__c,Principal__c,Principal__r.LastName,Post_Abbreviation__c,Status__c from CampaignMember where CampaignId=:this.c.Id and Access_Level__c='Full' and Principal__c<>null and Status__c IN ('Invited','Accepted','Declined','Cancelled') order by Status__c ASC ])
            {
                for(Contact cont:[Select id,Name from Contact where id=:camp.principal__c]){
                    for(CampaignMember campmem:[Select id,Status__c from CampaignMember where name=:cont.Name and  CampaignId=:this.c.Id Limit 1]){
                    PartnerName1=c.Name;
                    PartnerStatus1=camp.status__c;
                    wrapperCampList.add(new wrapperclass(camp,PartnerName1,PartnerStatus1));
                    //principalID.add(camp.Principal__c);
                    }
                }
            }
        
        return wrapperCampList;
        
    }
    
    public class wrapperclass
    {
        Public CampaignMember camp{get; set;}
        Public string PartnerName {get; Set;}
        Public String PartnerStatus{get; Set;}
        
        public wrapperclass(CampaignMember c,String PartnerName,String PartnerStatus)
        {
            this.camp=c;
            this.PartnerName=PartnerName;
            this.PartnerStatus=PartnerStatus;
        }
    }
    
}

Many thanks,
Saniya