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
alex_from_parisalex_from_paris 

SOQL Limit : how to modify this request so as not to meet limit ?

Hi

I have quite an easy need but I can't find a way to "massify" this request : issue from the fact that I have a parameter in my query specific to each Campaign_Commander_Account__c

It can be done either in a batch or in a trigger or ... so don't hesitate

I have about 7000 Campaign_Commander_Account__c object and about 300 Campaigns_Daily_Summary__c are attached to each Campaign_Commander_Account__c (so 210000 Campaigns_Daily_Summary__c : it can hit 50000 select row limit)

 

List<Campaign_Commander_Account__c> myccmdaccount_list=[select id,  Contract_Start_Date__c from Campaign_Commander_Account__c where Contract_Start_Date__c!=null];

AggregateResult[] groupedResults;

for (Campaign_Commander_Account__c myccmdaccount:myccmdaccount_list)

{  

groupedResults=[SELECT SUM(Number_of_messages_sent__c)nums from Campaigns_Daily_Summary__c where Date_Summary__c>=:myccmdaccount.Contract_Start_Date__c and  Campaign_Commander_Account_ID__c=:myccmdaccount.id]; 

 

myccmdaccount.Total_Message_sent__c=double.valueOf(groupedResults[0].get('nums'));

}

update myccmdaccount_list;

 

Thanks for your help

Regards

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

global class Updatemyccmdaccount implements Database.Batchable<SObject>

{

        AggregateResult[] groupedResults;

 

  global Updatemyccmdaccount()

        {

            system.debug('@@@____constructor() called ! ');

        }

       

        global Database.QueryLocator start(Database.BatchableContext ctx)

        {

            system.debug('@@@____start() called ! ');

            return Database.getQueryLocator([select id, Contract_Start_Date__c from Campaign_Commander_Account__c where Contract_Start_Date__c!=null]);

        }

 

        global void execute(Database.BatchableContext ctx, List<SObject> scope)

        {

            system.debug('@@@____execute() called ! ');

            List<Campaign_Commander_Account__c> ccmdaccountList = new List<Campaign_Commander_Account__c>();

            for(SObject sObj : scope)

                {

      Campaign_Commander_Account__c ccmdaccount = (Campaign_Commander_Account__c)sObj;

                  groupedResults=[SELECT SUM(Number_of_messages_sent__c)nums from Campaigns_Daily_Summary__c where Date_Summary__c>=:ccmdaccount.Contract_Start_Date__c and  Campaign_Commander_Account_ID__c=:ccmdaccount.id];

      ccmdaccount.Total_Message_sent__c=double.valueOf(groupedResults[0].get('nums'));

 

                  ccmdaccountList.add(ac);

                  //system.debug('@@@____Accounts updated : ' + ccmdaccountList.size());

                }

                update ccmdaccountList;

                system.debug('@@@____Number of Accounts updated : ' + ccmdaccountList.size());

        }

       

        global void finish(Database.BatchableContext ctx)

        {

            system.debug('@@@____finish() called ! ');

            system.debug('@@@@___Accounts successfuly updated !!!!');

        }

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

alex_from_parisalex_from_paris

Hi

I have tried to launch it in developer console and I have following error :

line 1, column 14: Global type must be contained inside of a global class

 

For that I have copied exactly your code and add at the end

Updatemyccmdaccount.Updatemyccmdaccount(); to launch it

 

I believe this is a dummy error but although I understand the principle of your code, I don't understand it from a "technical" point of view

Please help again

Regards

Alex