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
symantecAPsymantecAP 

Problem with scheduling Apex

Hi I have an apex classes which is scheduled 1a.m everyday. The apex class aborts and gives the following error

 

First error: SQLException [java.sql.SQLException: ORA-01013: user requested cancel of current operation
: select /*AggJoin*/ "AccountId",
"Id",
"Subject",
"OwnerId",
"RecordType__c",
"Purpose__c",
"WhoId",
"ActivityDate",
"ActivityDate.AUX",

 

Here is my code. Kindly help 

/*
Extension case#03698934
This scheduler will consider only the following Events.
Events where last modify date is yesterday and End date is less then today AND
Profile of Assigned To  = Apartments.com House AC, Apartments.com RM User, Apartments.com Standard User, Gannett Standard User, LA Times Standard User AND
Event Record Type = Standard Event OR (Event Record Type = Event (Contact Optional) AND Level – Type = “Leases 4 Lunch”,” Mgmt Co – Cold Call Visit”,”Property – Cold Call Visit”)
and update the account info on from the selected Events information  

*/

global class ContactLastActivityDateBatch implements Database.Batchable<sObject>{
public String query;

global database.querylocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(query);
}
    
global void execute(Database.BatchableContext BC, List<sObject> scope){
        List<Account> accList= new List<Account>();
     
       
        for(sObject s : scope){
        
        Account acc = (Account)s;
        System.debug('Rajan Testing date 1'+acc);
         if(acc.ActivityHistories.size() > 0 && (acc.Last_visit_date__c == null || acc.Last_visit_date__c <= acc.ActivityHistories[0].ActivityDate)){
            try{
                
               ActivityHistory act = acc.ActivityHistories;                 
               acc.Last_visit_subject__c = act.Subject;
               acc.Last_visit_date__c = act.ActivityDate;
               acc.Last_visit_assigned_to__c = act.Owner.Name;
               acc.Last_visit_record_type__c = act.RecordType__c;
               acc.Last_visit_purpose__c = act.Purpose__c;
               acc.Last_visit_level_type__c=act.Level_Type__c;
               acc.Last_visit_description__c=act.Description;
               
               //Populate only if who Id in Event is populated with a Contact Name.
               if(act.whoId != null && string.valueOf(act.whoId).startsWith('003')) 
               acc.Last_visit_contact_name__c = act.whoId;
               else
               acc.Last_visit_contact_name__c = null;
               //System.debug('Rajan Testing date 2'+c.Last_Activity_Date__c + act.ActivityDate);
                 accList.add(acc);             
            }
            catch(Exception ex){
                System.debug(ex.getMessage());
            }
        }
    }
    update accList;
    
    
    }
  global void finish(Database.BatchableContext BC){}  
}

 

/*Salesforce.com Extension#03698934
This class implements apex schedular interface to update Last Activity Date on Account
*/
global class updateAccountLastActivityDate implements Schedulable
{ 
    global void execute(SchedulableContext ctx){
        
        ContactLastActivityDateBatch accBatch = new ContactLastActivityDateBatch ();
    
        accBatch.query ='select Name, Last_visit_subject__c,Last_visit_level_type__c,Last_visit_description__c,Last_visit_date__c, Last_visit_assigned_to__c, Last_visit_record_type__c, Last_visit_purpose__c,  Last_visit_contact_name__c,'
                        +'(Select Subject,Owner.Name,RecordType__c,Purpose__c, whoId ,AccountId,id,ActivityDate,Level_Type__c,Description from ActivityHistories where '
                        +'Custom_Profile_Name__c in (\'Apartments.com House AC\',\'Apartments.com RM User\',\'Apartments.com Standard User\',\'Gannett Standard User\',\'LA Times Standard User\')'
                        +' AND (RecordType__c=\'Standard Event\'  OR  (RecordType__c=\'Event (Contact Optional)\' AND Level_Type__c in (\'Leases 4 Lunch\',\'Mgmt Co - Cold Call Visit\',\'Property - Cold Call Visit\')))'
                        +' AND ActivityDate <= TODAY'
                        +' AND Isdeleted =false'
                        +' order by ActivityDate desc limit 1) from Account';                                   
                        
                         
        ID batchprocessid = Database.executeBatch(accBatch);
       
    }
}

 Thanks in Advance . 

grigri9grigri9

You should open up a case about that since it's an internal sf error. However, the problem is most likely with the query you're constructing. Can you try and run the query through anonymous apex and make sure that is is compiling into valid soql?

symantecAPsymantecAP

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

I get this error when i try to execute anonymous