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
Chinna SfdcChinna Sfdc 

Internal salesforce.com error

Hi Team,
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". Can any one please help me to acheive this error.

Here is my Batch Apex logic:

global class OpportunityCWDays implements Database.Batchable <Sobject>{    
    Public List<Opportunity> lstOpp;    
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'Select id, Name, StageName, Software_Product_Count__c, CW_in_Last_30_Days_Formula__c, CW_in_Last_30_Days_Workflow__c, CW_in_Last_730_Days_Formula__c, CW_in_Last_730_Days_Workflow__c from Opportunity Where StageName = \'S8- Closed Won\' AND Software_Product_Count__c > 0 AND ( ((CW_in_Last_30_Days_Formula__c = True AND CW_in_Last_30_Days_Workflow__c = False) OR (CW_in_Last_30_Days_Formula__c = False AND CW_in_Last_30_Days_Workflow__c = True)) OR ((CW_in_Last_730_Days_Formula__c = True AND CW_in_Last_730_Days_Workflow__c = False) OR (CW_in_Last_730_Days_Formula__c = False AND CW_in_Last_730_Days_Workflow__c = True))) ';       
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Opportunity> batch){ 
    lstOpp = new List<Opportunity>();
    for(Opportunity objOpp : batch){
        if(objOpp.CW_in_Last_30_Days_Formula__c == True){
            objOpp.CW_in_Last_30_Days_Workflow__c = True;
        }
        else{//if(objOpp.CW_in_Last_30_Days_Formula__c == False){
            objOpp.CW_in_Last_30_Days_Workflow__c = False;
            }
        if(objOpp.CW_in_Last_730_Days_Formula__c == True){
            objOpp.CW_in_Last_730_Days_Workflow__c = True;
        }
        else{//if(objOpp.CW_in_Last_730_Days_Formula__c == False){
            objOpp.CW_in_Last_730_Days_Workflow__c = False;
        }
        lstOpp.add(objOpp);
    }
    Database.SaveResult[] dbOppList = Database.Update(lstOpp,false);   
    //System.debug('Update CW ' + dbOppList[].Id);
    for(Database.SaveResult sr : dbOppList){
        if(sr.isSuccess()){
            // Operation was successful, so get the ID of the record that was processed
            System.debug('Successfully Updated OPP ID: ' + sr.getId());
        }       
        else{
            // Operation failed, so get all errors                
            for(Database.Error err : sr.getErrors()){
                System.debug('The following error has occurred.');                    
                System.debug(err.getStatusCode() + ': ' + err.getMessage());
                System.debug('Users fields that affected this error: ' + err.getFields());
            }
        }
    }
  }
    global void finish(Database.BatchableContext BC){
        
    }  
}

Thanks
James LoghryJames Loghry
Hi Chinna

Unfortunately, "Internal Server Errors" are VERY difficult to debug.  They typically involve a call into Salesforce to look up a "Gack" (only a few internal Salesforce employees have the ability do do this).  Even when they're able to lookup the Gack, it's not always evident what the root cause is.

However, if I were you, I would start with stripping out much of your batch class and then start adding pieces back in one by one into your batch class, so that you can narrow down the culprit.

For instance I would check the following:
1) Does the batch class work with just the query and a simple system.debug(batch);
2) Does the batch class work with just theq query, a simple system.debug, and adding the batch opportunities to a list?
3) Does the batch class work with just the query, system debug, adding to the list and doing an update lstOpp?
4) Does the batch class work with the query, system debug, adding to the list, and doing the partial processing?

After looking at your code though, it looks like it *may* be that you're using a member variable in your batch class when you don't need to.  I suspect that this is the exception you're running into, although it could also be the fact you're using partial processing (Database.update(list,false)).
 
global class OpportunityCWDays implements Database.Batchable <Sobject>{    
    //You dont need this..
    //Public List<Opportunity> lstOpp;    
    
    global Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'Select id, Name, StageName, Software_Product_Count__c, CW_in_Last_30_Days_Formula__c, CW_in_Last_30_Days_Workflow__c, CW_in_Last_730_Days_Formula__c, CW_in_Last_730_Days_Workflow__c from Opportunity Where StageName = \'S8- Closed Won\' AND Software_Product_Count__c > 0 AND ( ((CW_in_Last_30_Days_Formula__c = True AND CW_in_Last_30_Days_Workflow__c = False) OR (CW_in_Last_30_Days_Formula__c = False AND CW_in_Last_30_Days_Workflow__c = True)) OR ((CW_in_Last_730_Days_Formula__c = True AND CW_in_Last_730_Days_Workflow__c = False) OR (CW_in_Last_730_Days_Formula__c = False AND CW_in_Last_730_Days_Workflow__c = True))) ';       
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext BC, List<Opportunity> batch){ 
    //Cast and initialize in the execute method instead...
    //Typically you'd do this.. List<Opportunity> lstOpp = new List<Opportunity>();
    //BUT we don't actually need a new list of opportunities and can just use batch..
    for(Opportunity objOpp : batch){
         //Simplified your boolean logic...
         objOpp.CW_in_Last_30_Days_Workflow__c = objOpp.CW_in_Last_30_Days_Formula__c;
         objOpp.CW_in_Last_730_Days_Workflow__c = objOpp.CW_in_Last_730_Days_Formula__c;
    }

    Database.SaveResult[] dbOppList = Database.Update(batch,false);

    //Debugging errors is kinda pointless like this.. so commenting it out.   
    /*for(Database.SaveResult sr : dbOppList){
        if(sr.isSuccess()){
            // Operation was successful, so get the ID of the record that was processed
            System.debug('Successfully Updated OPP ID: ' + sr.getId());
        }       
        else{
            // Operation failed, so get all errors                
            for(Database.Error err : sr.getErrors()){
                System.debug('The following error has occurred.');                    
                System.debug(err.getStatusCode() + ': ' + err.getMessage());
                System.debug('Users fields that affected this error: ' + err.getFields());
            }
        }
    }*/
  }
    global void finish(Database.BatchableContext BC){
        
    }  
}

Give that a whirl and see if it resolves your Internal Server Error.  Good luck!
James LoghryJames Loghry
I should also mention.. when you post code on the forums, please use the code formatting button (< >).  Thanks!
Gordon EngelGordon Engel
If you post the ISE number I will look it up for you.
Chinna SfdcChinna Sfdc
@James Loghry...Thanks For your help. I have tried your logic not getting the ISE Error.But Records are not getting update.Can you please help me on this issue.

Thanks
Chinna SfdcChinna Sfdc
@Gordon Engel,  we are getting like this. CUMULATIVE_PROFILING Class.OpportunityCWDays.execute: line 26, column 1: com.salesforce.api.Database.update(List<Opportunity>, Boolean): executed 1 time in 35562 ms.

Thanks
Gordon EngelGordon Engel
Internal Server Errors are usually formatted like this:  

Error Number: 1864495260-204529 (245827274)

Do you have an error number I can refer to, or is this just a normal application error in your logs?
Chinna SfdcChinna Sfdc
@Gordon Engel,  Am sorry I didn't get any Errornumber as mentioned above.we are getting normal application error which we got from debug logs.Can you please help me on this probelm.That would great help for us.

Thanks
Chinna SfdcChinna Sfdc
@Gordon Engel.   Is there any posibility to overcome this issue.Can you please help us on this.

Thanks
Gordon EngelGordon Engel
The "CUMULATIVE_PROFILING" message is not an error.  It is part of the profiling debug logic, and it is telling you how long your code spent in the class OpportunityCWDays.  You can make the message go away by reducing your logging level to something other than "Finest".

You Internal Server Error is caused by something else.  Do you see any other errors in the logs?
 
Chinna SfdcChinna Sfdc
Hi Gordon Engel,

We have facing below internal salesforce.come error. 
"An error has occurred while processing your request. The salesforce.com support team has been notified of the problem. If you believe you have additional information that may be of help in reproducing or correcting the error, please contact Salesforce Support. Please indicate the URL of the page you were requesting, any error id shown on this page as well as any other related information. We apologize for the inconvenience. 

Thank you again for your patience and assistance. And thanks for using salesforce.com!
Error ID: 1690312637-24627 (-698368428)"

Can you please help me on this.

Thanks 
Gordon EngelGordon Engel
I'm not 100% sure, but I think this error occurs if you try to create an Opportunity and a validation rule fails.  This leaves the Opporunity in a bad state.  You could try disabling some validation rules (in sandbox) and see which one(s) trigger the error.

The exception is:

sales.opportunity.InvalidRollupException: common.exception.SfdcSqlException: ORA-20423: invalid opp rollup count: 1

I think this is a PLSQL routine throwing an exception because an assertion failed.  If you can't find a validation rule that causes the error, Salesforce Support could run some "scrutiny" tests to ensure that your data is clean.
Chinna SfdcChinna Sfdc
Thanks for your all help on this @Gordon Engel