2

Problem

i'm having an issue in a Batch Process. It's have been working properly since January, but in the last days i'm getting an Internal SalesForce Error. The error line is inside a Query which is called in a Batch process, which executes diary.

Code:

private static final String INVOICE_NUMBER_FORMAT = '/TEST_'; 
private static Integer dateYear = Date.today().year(); 
private static Integer invoiceNumber = null;

private static void setupInvoiceNumber(){
    String key = dateYear + UpdateInvoiceBatchHelper.INVOICE_NUMBER_FORMAT + '%';
    UpdateInvoiceBatchHelper.invoiceNumber = 0;
    for(AggregateResult result : [SELECT max(Invoice_Number__c)numero 
                                FROM kugo2p__KugamonInvoice__c 
                                WHERE Invoice_N__c LIKE :key 
                                AND Invoice_Year__c > 0 AND Invoice_Number__c > 0 ]){
        UpdateInvoiceBatchHelper.invoiceNumber = (Integer)result.get('numero');
        break;
    } 
}

In the end the query seems like this:

SELECT max(Invoice_Number__c)numero FROM kugo2p__KugamonInvoice__c WHERE Invoice_N__c LIKE '2015/RR_%' AND Invoice_Year__c > 0 AND Invoice_Number__c > 0

Trying in my developer console this very Query sometimes work and sometimes not. When it works we get over 4600 rows , but when It doesn't work we get this message: NO RESPONSE FROM SERVER Today in the morning it did'nt work, but now it's working.

DEBUG:

Apex Debug Log Detail User Salesforce Administrator Date 26/08/2015 22:03:17 CEST Status Internal Salesforce.com Error Application Unknown Request Type Api Operation SerialBatchApexRangeChunkHandler Duration (ms) 127.151 Log Size (bytes) 9.069 Log
28.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO 22:01:10.251 (251532466)|EXECUTION_STARTED 22:01:10.251 (251614875)|CODE_UNIT_STARTED|[EXTERNAL]|01pD0000001Guik|UpdateInvoiceBatch

[...]

22:01:12.686 (2686519388)|METHOD_EXIT|[1]|UpdateInvoiceBatchHelper 22:01:12.686 (2686566341)|METHOD_ENTRY|[69]|01pD0000001Guil|UpdateInvoiceBatchHelper.processInvoice(kugo2p__KugamonInvoice__c) 22:01:12.686 (2686656124)|SYSTEM_MODE_ENTER|false 22:01:12.686 (2686701927)|METHOD_ENTRY|[24]|01pD0000001Guil|UpdateInvoiceBatchHelper.assignNextInvoiceNumber(kugo2p__KugamonInvoice__c) 22:01:12.686 (2686788797)|METHOD_ENTRY|[48]|01pD0000001Guil|UpdateInvoiceBatchHelper.getNextInvoiceNumber() 22:01:12.686 (2686854833)|METHOD_ENTRY|[62]|01pD0000001Guil|UpdateInvoiceBatchHelper.setupInvoiceNumber() 22:01:12.686 (2686987555)|SYSTEM_METHOD_ENTRY|[73]|String.valueOf(Object) 22:01:12.687 (2687068922)|SYSTEM_METHOD_EXIT|[73]|String.valueOf(Object) 22:01:12.688 (2688214255)|SOQL_EXECUTE_BEGIN|[75]|Aggregations:0|SELECT MAX(Invoice_Number__c) numero FROM kugo2p__KugamonInvoice__c 22:03:17.086 (127086562646)|SYSTEM_MODE_EXIT|false

No further information in the Debug Log.

I think this issue could be a Timeout Error in the query response, but i don't know how to make a lighter or faster query. Could anyone help me?

Have a nice day!

1

You can create a Custom Setting to save the counter (max(invoice_number__c)) and create a Trigger to update the counter and in the batch you can read the value in the custom setting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.