2

Error Message

System.UnexpectedException: Error processing messages

Stack Trace

Class.System.Test.stopTest: line 24, column 1 Class.payout.BIgObj_Test.MyMethod: line 31, column 1

Batch Class

global class ArchiveALCTtoBigObj_Batch implements Database.Batchable<sObject>,Database.Stateful{

global final String paid;
global set <string> AdID = New set <string> ();
global ArchiveALCTtoBigObj_Batch(String pid){

    pa = pid;




}

global Database.QueryLocator start(Database.BatchableContext BC){
    DescribeSObjectResult describeResult = Account.getSObjectType().getDescribe();    
    List<String> fieldNames = new List<String>( describeResult.fields.getMap().keySet() );  
    String query =    ' SELECT ' +
        String.join( fieldNames, ',' ) +
        ' FROM ' +
        describeResult.getName()+
        ' WHERE ' +
        ' pa__c = :paid '; 
    System.debug('Al query = '+query);
    return Database.getQueryLocator(query);

}

global void execute(Database.BatchableContext BC, List<Account> scope){



    List <AccountBigObj__b> BObj_ALlist = new List<AccountBigObj__b>();


    for(Account AL : Scope ){

        AccountBigObj__b BObj_AL = new AccountBigObj__b();

        //Logic to assigning values from account to BigObject


        AdID.add(AL.ID);
        BObj_ALlist.add(BObj_AL);


    }

    If(BObj_ALlist.size()>0){
        database.insertImmediate(BObj_ALlist);

    }
}

global void finish(Database.BatchableContext BC){

    ArchiveCTtoBigObj_Batch ACT = new ArchiveCTtoBigObj_Batch(AdID);
    Database.executeBatch( ACT, 1 );
}

Batch Class 2

global class ArchiveCTtoBigObj_Batch implements database.Batchable<SObject>,Database.allowscallouts {

public set <string> ArchiveALCTtoBigObj_Batchid  = New set <string> ();

global ArchiveCTtoBigObj_Batch(set <String> ALId){

    this.ArchiveALCTtoBigObj_Batchid = ALId;

}

global database.QueryLocator Start(Database.BatchableContext bc) {


    DescribeSObjectResult describeResult = Contact.getSObjectType().getDescribe();    
    List<String> fieldNames = new List<String>( describeResult.fields.getMap().keySet() );  
    String query =    ' SELECT ' +
        String.join( fieldNames, ',' ) +
        ' FROM ' +
        describeResult.getName()+
        ' WHERE ' +
        ' AccountId = :ArchiveALCTtoBigObj_Batchid '; 

    return Database.getQueryLocator(query);



}
global void Execute(Database.BatchableContext bc, list<Contact>Scope){

    System.debug('Scope = '+Scope);
    List<ContactBigObject__b> BigObj_CTList = new List<ContactBigObject__b>();

    For(Contact CN : Scope){

       ContactBigObject__b BigObj_CT = new ContactBigObject__b();
        //Logic to assigning values from object to bigObject
        BigObj_CTList.add(BigObj_CT);


        }
             If(BigObj_CTList.size()>0){
              System.debug('List is not Empty');
            database.insertImmediate(BigObj_CTList);

    }


}

global void finish(Database.BatchableContext BC){
}

Test Class

@isTest
public class BIgObj_Test {
    public testmethod static void MyMethod(){

        Id ART = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Ad').getRecordTypeId();



        Account A1 = new Account();
        A1.RecordTypeId = ART;
        A1.Name = 'Test Account';
        insert A1;

        Contact c1 = new Contact();
        c1.name = 'TestContact';
        c1.AccountId = A1.id;

        insert c1; 





        Test.startTest();

        ArchiveALCTtoBigObj_Batch ALBOBatch1 = New ArchiveALCTtoBigObj_Batch (A1.id);
        Database.executeBatch(ALBOBatch1,1);



        Test.stopTest();        



    }
5

I simply wrote a test class to insert a big object.

@IsTest
    static void testBehavior() {


        Test.startTest();
        Database.insertImmediate(new BigAccount__b(Account_Name__c= 'My Big Account'));
        Test.stopTest();
    }

Nothing fancy, plain simple, and when I run it I get the error.

Error 500/Server Error - UNKNOWN_EXCEPTION: An unexpected error occurred. Please include this ErrorId if you contact support: 833447077-35221 (1201933628)

I tried querying my Big Object table, and I could still see the test record being inserted in the actual database. This is one of the cases where test context does not respect execution context boundaries.

FROM SF docs:

Apex tests that use mixed DML calls are not allowed and fail. If you write only to the Big Object, the test inserts bad data into the target big object that you have to delete manually. To contain test DML calls to the target big object, use a mocking framework with the batch Apex stub API instead.

So apprently the testing framework is yet to be matured to test anything related to Big Objects. You have to use mocking frame from fflib or standard sf stub api.

  • 1
    interesting; fflib Selector and Unit of Work layers plus ApexMocks will come in real handy for the OP. Why I use that pattern all day, all night – cropredy Mar 13 at 16:36
  • @cropredy I use UOW, its pretty good, for rest of fflib features, there is a steep learning curve and not many blogs are available to guide. – Pranay Jaiswal Mar 13 at 16:45
  • 1
    Best resource for me to learn was Force.com Enterprise Architecture 2nd Edition Chapters 4-7, 12. My copy was heavily marked up by me when I was learning. There is also a Trailhead available. I'd never go back to anything else – cropredy Mar 13 at 17:08
  • Hi @PranayJaiswal thank you for your time and helping me ! I'm Just curious that my functionality is of Batch Apex do I need to insert BigObject manually ? – Nikhil Pandit Mar 19 at 7:45
  • It fine. You can insert records in batch. Its just that you cant insert records in test context for big object – Pranay Jaiswal Mar 19 at 9:52

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.