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
avinash dhankeavinash dhanke 

create apex class to insert account object record to big object

global class bigObject implements database.Batchable<Sobject> {
    
    global database.QueryLocator start(database.BatchableContext bc){
        string query = 'select id,name,Industry from Account';
        return database.getQueryLocator(query);
    }
    global void execute(database.BatchableContext bc , list<account> scope ){
        list<Customer_Interaction__b> customer = new list<Customer_Interaction__b>();
        for(account a : scope){
            Customer_Interaction__b cusint = new Customer_Interaction__b();
            a.Id=cusint.Id;
            a.Name=cusint.Level_Achieved__c;
            a.Industry=cusint.Game_Platform__c;
            
            customer.add(cusint);
            
        }
        insert customer;
    }
    global void finish(database.BatchableContext bc){
        
    }
}
Raj VakatiRaj Vakati
Do it like below .database.insertImmediate(cusint) for Big Objects 
global class bigObject implements database.Batchable<Sobject> {

global database.QueryLocator start(database.BatchableContext bc){
	string query = 'select id,name,Industry from Account';
	return database.getQueryLocator(query);
}
global void execute(database.BatchableContext bc , list<account> scope ){
	list<Customer_Interaction__b> customer = new list<Customer_Interaction__b>();
	for(account a : scope){
		Customer_Interaction__b cusint = new Customer_Interaction__b();
		a.Id=cusint.Id;
		a.Name=cusint.Level_Achieved__c;
		a.Industry=cusint.Game_Platform__c;
		
		customer.add(cusint);
		
	}
database.insertImmediate(cusint);
}
global void finish(database.BatchableContext bc){
	
}
}

 

 
Raj VakatiRaj Vakati
I think you can't able to use the QueryLocator in the batch apex start method with big objects .. 
The QueryLocator approach is not supported for any Virtual Entities that don't return a total size count. This is because BatchApex needs to know the total number of records to create the correct number of jobs.

Instead, use an Iterator with the batch 
avinash dhankeavinash dhanke
not working any other solution i want to inser account data into big object
Maharajan CMaharajan C
Hi Avinash,

I thinks you no need to go to iterator type BC if you are querying the data from big object then you have to choose that approach.

You made some small mistakes in the batch class please change those and try that:

global class bigObject implements database.Batchable<Sobject> {
    
    global database.QueryLocator start(database.BatchableContext bc){
        string query = 'select id,name,Industry from Account';
        return database.getQueryLocator(query);
    }
    global void execute(database.BatchableContext bc , list<account> scope ){
        list<Customer_Interaction__b> customer = new list<Customer_Interaction__b>();
        for(account a : scope){
            Customer_Interaction__b cusint = new Customer_Interaction__b();
            cusint.Id__c = a.Id; //create the custom field to store the Account Id.
            cusint.Level_Achieved__c = a.Name;
            cusint.Game_Platform__c = a.Industry;

            
            customer.add(cusint);
            
        }
        insert customer;   // or try database.insertImmediate(cusint);
    }
    global void finish(database.BatchableContext bc){
        
    }
}

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj.
Amit Chaudhary 8Amit Chaudhary 8
Try to update your code like below
global class bigObject implements database.Batchable<Sobject> {
	global database.QueryLocator start(database.BatchableContext bc){
		string query = 'select id,name,Industry from Account';
		return database.getQueryLocator(query);
	}
	global void execute(database.BatchableContext bc , list<account> scope ){
		
		list<Customer_Interaction__b> customer = new list<Customer_Interaction__b>();
		
		for(account a : scope){
			Customer_Interaction__b cusint = new Customer_Interaction__b();
			cusint.Id=a.Id;
			cusint.Level_Achieved__c=a.Name;
			cusint.Game_Platform__c=a.Industry;
			customer.add(cusint);
		}
		
		database.insertImmediate(customer);
	}
	global void finish(database.BatchableContext bc){
	}

}
Let us know if this will help you
 
avinash dhankeavinash dhanke
@amit chaudhary 
when i tried this code its giving mi following error
First error: Invalid id value for this SObject type: 0017F00000M5TxmQAF

When i replace cusint.Id=a.Id; with cusint.Account__c     = a.Id; the error is gone and the batch gets executed successfully however when i query big object its not refelecting any data there. 

Can you please let me know if anything else needs to be done

Thank
Amit Chaudhary 8Amit Chaudhary 8
global class bigObject implements database.Batchable<Sobject> {
	global database.QueryLocator start(database.BatchableContext bc){
		string query = 'select id,name,Industry from Account';
		return database.getQueryLocator(query);
	}
	global void execute(database.BatchableContext bc , list<account> scope ){
		
		list<Customer_Interaction__b> customer = new list<Customer_Interaction__b>();
		
		for(account a : scope){
			Customer_Interaction__b cusint = new Customer_Interaction__b();
			//cusint.Id=a.Id;
			cusint.Level_Achieved__c=a.Name;
			cusint.Game_Platform__c=a.Industry;
			customer.add(cusint);
		}
		
		database.insertImmediate(customer);
	}
	global void finish(database.BatchableContext bc){
	}

}
Try above code. Try to comment below line
//cusint.Id=a.Id;
 
avinash dhankeavinash dhanke
@amit choudhary .
this is not working. am i doing something wrong.

Thanks
Amit Chaudhary 8Amit Chaudhary 8
What error you are getting now ?