• Scorpio
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies

Hi,

 

I have a situation here. I have a custom object lets say SAAS_Profile__c. It has 2 text fields that contain queries like :

 

Query_Total_Records__c  : Select Count() FROM Case where RecordTypeID='012a0000001RRKBAA4' 

 

Query_Records_Per_Week__c : Select Count() FROM Case where RecordTypeID='012a0000001RRKBAA4'  and CreatedDate = LAST_N_DAYS:7

 

Now my requirement is I have to get all the rows of   SAAS_Profile__c object(total rows less than 100). And for each row returned I have to execute these 2 queries and update 2 fields : Records_pWeek__c(for weekly counts) and Records_Total__c (Total record count). These 2 fields are for statistics purposes and we intend to run this batch job on a weekly basis. Each row of this SAAS_Profile__c object queries on different objects both custom and standard . Here is the batch job that I have written:

 

global class batchSAASProfileUpdate implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
String query = 'SELECT Id,Name,Query_Records_Per_Week__c,Query_Total_Records__c,Records_pWeek__c,Records_Total__c FROM SAAS_Profile__c where Query_Records_Per_Week__c !=\'\' and Query_Total_Records__c != \'\') ';
system.debug('Query String : '+query);
return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, List<SAAS_Profile__c> scope)
{
system.debug('******************Inside execute');
for(SAAS_Profile__c s : scope){
String queryPerWeek = s.Query_Records_Per_Week__c;
String queryTotalRec = s.Query_Total_Records__c;
system.debug('****************name :'+ s.name +'values : queryPerWeek :'+queryPerWeek +' queryTotalRec '+queryTotalRec );
try{
s.Records_pWeek__c = Database.countQuery(queryPerWeek);
s.Records_Total__c = Database.countQuery(queryTotalRec);
system.debug('****************values : s.Records_pWeek__c :'+s.Records_pWeek__c+' s.Records_Total__c '+s.Records_Total__c );
update s;
}
catch(Exception e){
system.debug('********Exception occured' + e.getMessage());
}
}

}
global void finish(Database.BatchableContext BC)
{
}
}

 

This batch job is working for the records that have total count values < 50,000. Its failing for the count() more than that. I am stuck here. I dont know how to work around this issue. Any help is really appreciated. This is really critical for us now!

 

 

Hi,

 

I have a situation here. I have a custom object lets say SAAS_Profile__c. It has 2 text fields that contain queries like :

 

Query_Total_Records__c  : Select Count() FROM Case where RecordTypeID='012a0000001RRKBAA4' 

 

Query_Records_Per_Week__c : Select Count() FROM Case where RecordTypeID='012a0000001RRKBAA4'  and CreatedDate = LAST_N_DAYS:7

 

Now my requirement is I have to get all the rows of   SAAS_Profile__c object(total rows less than 100). And for each row returned I have to execute these 2 queries and update 2 fields : Records_pWeek__c(for weekly counts) and Records_Total__c (Total record count). These 2 fields are for statistics purposes and we intend to run this batch job on a weekly basis. Each row of this SAAS_Profile__c object queries on different objects both custom and standard . Here is the batch job that I have written:

 

global class batchSAASProfileUpdate implements Database.Batchable<sObject>
{
global Database.QueryLocator start(Database.BatchableContext BC)
{
String query = 'SELECT Id,Name,Query_Records_Per_Week__c,Query_Total_Records__c,Records_pWeek__c,Records_Total__c FROM SAAS_Profile__c where Query_Records_Per_Week__c !=\'\' and Query_Total_Records__c != \'\') ';
system.debug('Query String : '+query);
return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, List<SAAS_Profile__c> scope)
{
system.debug('******************Inside execute');
for(SAAS_Profile__c s : scope){
String queryPerWeek = s.Query_Records_Per_Week__c;
String queryTotalRec = s.Query_Total_Records__c;
system.debug('****************name :'+ s.name +'values : queryPerWeek :'+queryPerWeek +' queryTotalRec '+queryTotalRec );
try{
s.Records_pWeek__c = Database.countQuery(queryPerWeek);
s.Records_Total__c = Database.countQuery(queryTotalRec);
system.debug('****************values : s.Records_pWeek__c :'+s.Records_pWeek__c+' s.Records_Total__c '+s.Records_Total__c );
update s;
}
catch(Exception e){
system.debug('********Exception occured' + e.getMessage());
}
}

}
global void finish(Database.BatchableContext BC)
{
}
}

 

This batch job is working for the records that have total count values < 50,000. Its failing for the count() more than that. I am stuck here. I dont know how to work around this issue. Any help is really appreciated. This is really critical for us now!