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
jkucerajkucera 

FATAL_ERROR|Internal Salesforce.com Error after existing Database.getQueryLocator()

I just added a NameSpace to my Developer org, and now 2 tests fail with an awful error message.  I'm tempted to just remove the tests so I can actually upload the package.

 

The code hasn't changed, and tests still pass in installed orgs that have the unmanaged package.

 

Error debug lines:

 

21:18:53.48|USER_DEBUG|[7,9]|DEBUG|query string: Select Id, recordId__c FROM chttrunfollow__UnfollowQueue__c WHERE scheduledUnfollowDate__c<= TODAY AND IsDeleted=FALSE
21:18:53.48|METHOD_EXIT|[7,9]|system.debug(String)
21:18:53.48|METHOD_ENTRY|[8,52]|database.query(String)
21:18:53.48|SOQL_EXECUTE_BEGIN|[8,52]|Aggregations:0|Select Id, recordId__c FROM chttrunfollow__UnfollowQueue__c WHERE scheduledUnfollowDate__c<= TODAY AND IsDeleted=FALSE
21:18:53.51|SOQL_EXECUTE_END|[8,52]|Rows:3
21:18:53.51|METHOD_EXIT|[8,52]|database.query(String)
21:18:53.51|METHOD_ENTRY|[9,9]|system.debug(String)
21:18:53.51|METHOD_ENTRY|[9,31]|LIST<chttrunfollow__UnfollowQueue__c>.size()
21:18:53.52|METHOD_EXIT|[9,31]|LIST<chttrunfollow__UnfollowQueue__c>.size()
21:18:53.52|USER_DEBUG|[9,9]|DEBUG|size: 3
21:18:53.52|METHOD_EXIT|[9,9]|system.debug(String)
21:18:53.52|METHOD_ENTRY|[10,16]|Database.getQueryLocator(String)
21:18:53.52|SOQL_EXECUTE_BEGIN|[10,16]|Aggregations:0|Select Id, recordId__c FROM chttrunfollow__UnfollowQueue__c
21:18:53.77|SOQL_EXECUTE_END|[10,16]|Rows:3
21:18:53.77|METHOD_EXIT|[10,16]|Database.getQueryLocator(String)
21:18:53.105|FATAL_ERROR|Internal Salesforce.com Error

 I saw this thread, and added my namespace, but no luck:

http://community.salesforce.com/t5/Visualforce-Development/Visualforce-An-internal-server-error-has-occurred/m-p/167376

 

Class that produces the above error:

 

global with sharing class UnfollowProcessUnfollowQueueBatch implements Database.Batchable<sObject>{

   global String sObjectQuery ='Select Id, recordId__c FROM chttrunfollow__UnfollowQueue__c WHERE scheduledUnfollowDate__c<= TODAY' ;
   
   global Database.QueryLocator start(Database.BatchableContext BC){
        system.debug('query string: '+sObjectQuery);
        List<chttrunfollow__UnfollowQueue__c> uq = database.query(sObjectQuery);
        system.debug('size: '+uq.size());
        return Database.getQueryLocator(sObjectQuery);
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
        Set<Id> recordIds=new Set<Id>();
  
        for(sObject s : scope){
            recordIds.add(String.ValueOf(s.get('recordId__c')));
        }//for
    
        //This is the method that unfollows all people from the records 
        try{
            UnfollowRecords.UnfollowRecordsButtonAction(recordIds);
            delete scope;
        } catch (Exception e) {
        }//try
   }

   global void finish(Database.BatchableContext BC){
       AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email from AsyncApexJob where Id =:BC.getJobId()];
  }

}//UnfollowRecordsFromDelayQueueBatch

Other Class that calls this class:

 

global with sharing class unfollowTryBatchJobsAgain{

    public static void unfollowTryBatchJobsAgain(){
        Integer numBatchApexJobsLimit=5;//at time of coding, there are at most 5 concurrent batch apex jobs in any org
        List<AsyncApexJob> numBatchJobs = [SELECT Id, Status FROM AsyncApexJob WHERE Status = 'Queued' OR Status = 'Processing'];

        //This is the number of jobs that can be queued up by this method
        Integer numJobsAvailable=numBatchApexJobsLimit - numBatchJobs.size();

        if(numJobsAvailable>0){
            List<UnfollowBatchJobsQueue__c> batchJobsQueued=[SELECT Id, IsDeleted, delayJob__c, delayRulesIncluded__c, evalateEachRecordForDaysDelay__c, numRulesUsedInThisObject__c, objectName__c, sObjectQuery__c FROM UnfollowBatchJobsQueue__c WHERE IsDeleted=FALSE ORDER BY  CreatedDate ASC];
            //Goal here is to process the delay queue first as it's more important than the others. Rather than do 2 queries, it's handled with variables here:
            Integer delayJobNum=1000;//initialize to huge number as a backup
            for (Integer i=0;i<batchJobsQueued.size();i++){
                if (batchJobsQueued[i].delayJob__c==TRUE){
                    delayJobNum=i;
                    break;
                }//if 2
            }//for 1
            
            for(Integer i=0; i<numJobsAvailable && i<batchJobsQueued.size(); i++){
                //if this is the high priority "delayed records scheduled for unfollow today" job, do it first
                if (delayJobNum!=1000){
                    UnfollowProcessUnfollowQueueBatch unfollowDelayedRecords= new UnfollowProcessUnfollowQueueBatch();
                    unfollowDelayedRecords.sObjectQuery=batchJobsQueued[delayJobNum].sObjectQuery__c;
                    try{
                        Id unfollowRulesProcessId = Database.executeBatch(unfollowDelayedRecords, 200); 
                        delete batchJobsQueued[delayJobNum];
                    } catch(exception e){
//                        system.debug('Either the batch failed or the job deletion from teh queue failed: '+e);
                    }//try
                } else if(batchJobsQueued[i].delayRulesIncluded__c==FALSE){
                 //is this the simple case with no "days delay" rules?
                    UnfollowRecordsBatch  unfollowRecords= new UnfollowRecordsBatch();
                    unfollowRecords.ObjectName=batchJobsQueued[i].objectName__c;
                    unfollowRecords.numRulesUsedInThisObject=batchJobsQueued[i].numRulesUsedInThisObject__c.intValue();
                    unfollowRecords.sObjectQuery =  batchJobsQueued[i].sObjectQuery__c;
                
                    try{
                        Id unfollowRulesProcessId = Database.executeBatch(unfollowRecords, 200); 
                        delete batchJobsQueued[i];
                    } catch(exception e){
//                        system.debug('Either the batch failed or the job deletion from the queue failed: '+e);
                    }//try
                } else {
                //else it's the more complex case where we need to check for the unfollow date
                    UnfollowQueueDelayRecordsBatch queueDelayRecords= new UnfollowQueueDelayRecordsBatch();
                    queueDelayRecords.ObjectName=batchJobsQueued[i].objectName__c;
                    queueDelayRecords.sObjectQuery =  batchJobsQueued[i].sObjectQuery__c;
                    queueDelayRecords.evalateEachRecordForDaysDelay=batchJobsQueued[i].evalateEachRecordForDaysDelay__c;
                    if(queueDelayRecords.evalateEachRecordForDaysDelay==TRUE){
//let's cross our fingers that the rule criteria didn't change between when this job first ran and now :(  
//Will the code fail elegantly if the rules were changed?
//I'd rather not create a 3rd queue just to save the state of the rules due to stupid batch apex limits
                        queueDelayRecords.delayRules=[Select Id, ObjectName__c, Active__c, FieldName__c, FieldType__c, Operator__c, Value__c, DaysDelay__c FROM UnfollowRule__c WHERE DaysDelay__c>0 AND Active__c = TRUE AND objectName__c=:queueDelayRecords.ObjectName]; 
                    }//if 3

                    try{
                        Id unfollowRulesProcessId = Database.executeBatch(queueDelayRecords, 200); 
                        delete batchJobsQueued[i];
                    } catch(exception e){
//                        system.debug('Either the batch failed or the job deletion from the queue failed: '+e);
                    }//try
                }//if 2
            }//for 1
        }//if 1
        
/*                        
        //This will store the job definition for the jobs over the numBatchApexJobsLimit to be run later
        List<UnfollowBatchJobsQueue__c> batchJobsQueued=new List<UnfollowBatchJobsQueue__c>();

        List<UnfollowRule__c> activeNonDelayedRules=[Select Id, ObjectName__c, Active__c, FieldName__c, FieldType__c, Operator__c, Value__c, DaysDelay__c FROM UnfollowRule__c WHERE (DaysDelay__c<1 OR DaysDelay__c=null) AND Active__c = TRUE];
        
        //now count the # rules for each object to pass into the email later
        For (UnfollowRule__c rule:activeNonDelayedRules){
            List<UnfollowRule__c> rules=new List<UnfollowRule__c>();
            if(objectRulesMap.containsKey(rule.ObjectName__c)){
                //get the existing rules in the map & add the new one
                rules=objectRulesMap.get(rule.ObjectName__c);
                rules.add(rule);
                objectRulesMap.remove(rule.ObjectName__c);
                objectRulesMap.put(rule.ObjectName__c, rules);
            } else {
                rules.add(rule);
                objectRulesMap.put(rule.ObjectName__c,rules);
            }//if 1
        }//for 1

        //Now queue up all the batch jobs
        for (String objectName:objectRulesMap.keyset()){
            //First check if there's a slot available - max of 5 concurrent jobs across all apps
            addFieldNames=FALSE;            
            query=buildQuery(objectName, objectRulesMap.get(objectName), addFieldNames);
            if(numJobsAvailable>0){
                numJobsAvailable--;//subtract one from the limit
                UnfollowRecordsBatch  unfollowRecords= new UnfollowRecordsBatch();
                unfollowRecords.ObjectName=objectName;
    
                unfollowRecords.numRulesUsedInThisObject=objectRulesMap.get(objectName).size();
                unfollowRecords.sObjectQuery =  query;
//                system.debug('The sObjectQuery string is: '+unfollowRecords.sObjectQuery);
                
                Id unfollowRulesProcessId = Database.executeBatch(unfollowRecords, 200); 
            }else{
                String sObjectQuery = query;
//                system.debug('There are 5 batch jobs already running, so this job is not scheduled.  Delay Job: TRUE, Object: '+objectName+', # Rules: '+objectRulesMap.get(objectName).size()+', Query: '+sObjectQuery );
                UnfollowBatchJobsQueue__c job=new UnfollowBatchJobsQueue__c(delayJob__c=FALSE, delayRulesIncluded__c=FALSE, objectName__c=objectName, numRulesUsedInThisObject__c=objectRulesMap.get(objectName).size(), sObjectQuery__c=sObjectQuery);
                batchJobsQueued.add(job);
            }//if 1
        }//for 1
        try{
            if(batchJobsQueued.size()>0){
                insert batchJobsQueued;
            }//if 1
        }catch (DMLException e){
//            system.debug('The batch jobs were not added to the queue successfully, likely due to dupe object name.  Error: '+e);
        }//try
*/        
    }//unfollowTryBatchJobsAgain
}//unfollowTryBatchJobsAgain

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
_Prasu__Prasu_

In your code i saw that you are creating the query in String variable. You will required adding namespace prefix to each object as well as each fields or the fields on which query are made.

Ex:

 recordId__c should be 

chttrunfollow__recordId__c

 

String sObjectQuery ='Select Id, recordId__c FROM chttrunfollow__UnfollowQueue__c WHERE scheduledUnfollowDate__c<= TODAY' ;

All Answers

_Prasu__Prasu_

In your code i saw that you are creating the query in String variable. You will required adding namespace prefix to each object as well as each fields or the fields on which query are made.

Ex:

 recordId__c should be 

chttrunfollow__recordId__c

 

String sObjectQuery ='Select Id, recordId__c FROM chttrunfollow__UnfollowQueue__c WHERE scheduledUnfollowDate__c<= TODAY' ;
This was selected as the best answer
jkucera2jkucera2

That worked perfect!  Thanks for the help!

 

Thanks for taking the time to read my post & respond!

 

I'll mark as solved in the morning when I'm back on the vpn.

jkucera2jkucera2

For any of you following at home - make sure you use 2 underscores between the prefix & the object name.  That cost me an hour today

 

Wrong:

 

chttrunfolow_UnfollowTest__c;

 Right:

 

chttrunfolow__UnfollowTest__c;

 

Also, you can check for custom fields vs non-custom fields using string methods.  For example, you shouldn't add the prefx to CreatedDate.  

if(rule.FieldName__c.substring(rule.FieldName__c.length()-3)=='__c'){
                ruleSOQL+=testQueryNameSpaceAddition+rule.FieldName__c+' ';
            }else {
                ruleSOQL+=rule.FieldName__c+' ';
            }

 

 

 

sadasiva07sadasiva07

hi im also getting the same error could you help me out here . this my pice of code :

 

/******************************************************************************************
Name   : AutoArchivingArticles
 
Purpose: Archiving of Articles depend on the Archivedate which is in the "Archive_Date__c" custom field.
         Whcih is going to schedule.
         
********************************************************************************************/


global class AutoArchivingArticles implements Database.Batchable<SObject>{

    
    Public String query='select id from KnowledgeArticleVersion where publishStatus='+'\'online\'' + ' '+'And'+ ' '+'language ='+'\'en_US\'';
    
    global Database.QueryLocator start(Database.BatchableContext BC){       
             
            system.debug('___query__'+query);
            return Database.getQueryLocator('select id from KnowledgeArticleVersion where publishStatus='+'\'online\'' + ' '+'And'+ ' '+'language ='+'\'en_US\'');    
    }  
    
    global void execute(Database.BatchableContext BC, List<sObject> scope){
         system.debug('___query__'+scope);
        List<KnowledgeArticleVersion> kav= (List<KnowledgeArticleVersion>)scope;  
        
        list<ID> kavid= new list<ID>();
        
              
        // List of Type Issues Solutions
        list<Issues_Solutions__kav> KT_IS = new list<Issues_Solutions__kav>();

        // List of Type Newsletter
        list<Newsletter__kav> KT_NL = new list<Newsletter__kav >();
        
        // List of Type Policies Procedures
        list<Policies_Procedures__kav> KT_PP = new list<Policies_Procedures__kav>();
        
        // List of Type Documentation
        list<Documentation__kav> KT_Doc = new list<Documentation__kav>();
        
        // List of Type FAQs
        list<FAQs__kav> KT_FAQ = new list<FAQs__kav>();
        
        // List of Type Installation_Updates
        list<Installation_Updates__kav> KT_IU = new list<Installation_Updates__kav>();
        
        // List of Type News Alerts
        list<News_Alerts__kav> KT_NA = new list<News_Alerts__kav>();
        
        // List of Type System Requirements
        list<System_Requirements__kav> KT_SR = new list<System_Requirements__kav>();
        
        // Placeing the KnowledgeArticleVeriosn ID's into a list
        
        for(KnowledgeArticleVersion K:kav){
            kavid.add(K.id);
        }
        
        Date Current_Date=system.today();   
        KT_IS=[select id,Archive_Date__c,Title,ArticleNumber from Issues_Solutions__kav where id IN : kavid and publishStatus='online' And language ='en_US' And Archive_Date__c=:Current_Date];
        KT_NL=[select id,Archive_Date__c,Title,ArticleNumber from Newsletter__kav where id IN : kavid and publishStatus='online' And language ='en_US' And Archive_Date__c=:Current_Date ];
        KT_PP=[select id,Archive_Date__c,Title,ArticleNumber from Policies_Procedures__kav where id IN : kavid and publishStatus='online' And language ='en_US' And Archive_Date__c=:Current_Date];
        KT_Doc=[select id,Archive_Date__c,Title,ArticleNumber from Documentation__kav where id IN : kavid and publishStatus='online' And language ='en_US' And Archive_Date__c=:Current_Date ];
        KT_FAQ=[select id,Archive_Date__c,Title,ArticleNumber from FAQs__kav where id IN : kavid and publishStatus='online' And language ='en_US' And Archive_Date__c=:Current_Date ];
        KT_IU=[select id,Archive_Date__c,Title,ArticleNumber from Installation_Updates__kav where id IN : kavid and publishStatus='online' And language ='en_US' And Archive_Date__c=:Current_Date ];
        KT_NA=[select id,Archive_Date__c,Title,ArticleNumber from News_Alerts__kav  where id IN : kavid and publishStatus='online' And language ='en_US' And Archive_Date__c=:Current_Date ];
        KT_SR=[select id,Archive_Date__c,Title,ArticleNumber from System_Requirements__kav where id IN : kavid and publishStatus='online' And language ='en_US' And Archive_Date__c=:Current_Date ];
        
        
        //Placing the Ariticle numbers into a list
        
        list<String> lArticleNumber= new list<String>();
                
        for(Issues_Solutions__kav k1:KT_IS){
            system.debug('___date chking__'+k1.Archive_Date__c);
            if(k1.Archive_Date__c==system.today()){
                lArticleNumber.add(k1.ArticleNumber);
            }
        }
        
        for(Newsletter__kav k1:KT_NL){
            system.debug('___date chking__'+k1.Archive_Date__c);
            if(k1.Archive_Date__c==system.today()){
                lArticleNumber.add(k1.ArticleNumber);
            }
        }
        
        for(Policies_Procedures__kav k1:KT_PP){
            system.debug('___date chking__'+k1.Archive_Date__c);
            if(k1.Archive_Date__c==system.today()){
                lArticleNumber.add(k1.ArticleNumber);
            }
        }
        
        for(Documentation__kav k1:KT_Doc){
            system.debug('___date chking__'+k1.Archive_Date__c);
            if(k1.Archive_Date__c==system.today()){
                lArticleNumber.add(k1.ArticleNumber);
            }
        }
        
        for(FAQs__kav k1:KT_FAQ){
            system.debug('___date chking__'+k1.Archive_Date__c);
            if(k1.Archive_Date__c==system.today()){
                lArticleNumber.add(k1.ArticleNumber);
            }
        }
        
        for(Installation_Updates__kav k1:KT_IU){
            system.debug('___date chking__'+k1.Archive_Date__c);
            if(k1.Archive_Date__c==system.today()){
                lArticleNumber.add(k1.ArticleNumber);
            }
        }
        
        for(News_Alerts__kav k1:KT_NA){
            system.debug('___date chking__'+k1.Archive_Date__c);
            if(k1.Archive_Date__c==system.today()){
                lArticleNumber.add(k1.ArticleNumber);
            }
        }
        
        for(System_Requirements__kav k1:KT_SR){
            system.debug('___date chking__'+k1.Archive_Date__c);
            if(k1.Archive_Date__c==system.today()){
                lArticleNumber.add(k1.ArticleNumber);
            }
        }
        
       
        list<KnowledgeArticle>  listknow= new list<KnowledgeArticle> ();
        listknow=[select id,ArticleNumber from KnowledgeArticle where ArticleNumber IN : lArticleNumber ];
        
        
        for(KnowledgeArticle K:listknow){
            Date ScheduleDate= system.today();
            KbManagement.PublishingService.archiveOnlineArticle(K.id,ScheduleDate);
         }
                  
       }
       
       
       global void finish(Database.BatchableContext BC){
       }     
            
}

z_harika88z_harika88

Hi,

 

I am also facing the same issue while running batch apex.

Please update the solution if this issue has solved.

 

Thanks,

Harika.

sadasiva07sadasiva07

please post you code ...

z_harika88z_harika88

Hi,


I have created a batch apex class and executing that code using "Anonymous Block". I am monitoring the batch operations in debug logs and noticed the operation name as "SerialBatchApexRangeChunkHandler" with status "Internal Salesforce.com Error".

Here is the Batch Apex Code:

global class CS_Unpublish_PublishArticles implements Database.Batchable<sObject>,Database.Stateful
{
    global string query;
    global string kbStatus;
    global List<string> articleIdList;
    global Database.QueryLocator start(Database.BatchableContext bc)
    {
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, list<Article__kav> articleObjs)
    {
        try{
            System.debug('**********'+articleObjs.size());
            if(kbStatus=='Unpublish')
            {
                System.debug('Unpublish operation');
                for(integer i=0;i<articleObjs.size();i++)
                {
                    KbManagement.PublishingService.editOnlineArticle(articleObjs[i].KnowledgeArticleId, false);
                    System.debug('#############'+articleObjs[i].KnowledgeArticleId+articleObjs[i].PublishStatus);
                }
            }
            else if(kbStatus=='Publish')
            {
                System.debug('Publish operation');
                for(integer i=0;i<articleObjs.size();i++)
                {
                    KbManagement.PublishingService.publishArticle(articleObjs[i].KnowledgeArticleId, false);
                    System.debug('#############'+articleObjs[i].KnowledgeArticleId+articleObjs[i].PublishStatus);
                }
            }
        }
        catch(Exception e)
        {
            System.debug('****************'+e);
        }

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

 Below is the code that executes batch apex:

string ArticleIds='Insert article Id';
    CS_Unpublish_PublishArticles unpublishArticles=new CS_Unpublish_PublishArticles();
unpublishArticles.articleIdList=ArticleIds.split(' ');
    unpublishArticles.query='select KnowledgeArticleId,PublishStatus from Article__kav where KnowledgeArticleId In :articleIdList and PublishStatus=\'Online\'';
unpublishArticles.kbStatus='Unpublish';
    Database.executeBatch(unpublishArticles);

 I would like to know which code is causing the error.

 

Thanks,

Harika.

 

 

Prakash@SFDCPrakash@SFDC
Hi Harika,

Are you able to fix this issue ? Even i am also getting the same exception . 

Thanks
Prakash.
chirugantachiruganta
Hi Harika,

Are you able to fix this issue? I am also getting the same error. Please help me on this.