You need to sign in to do that
Don't have an account?
Laetitia Damen 9
How do write test class for batch class ?
Hi there!
I'm looking to write a class test for my batch. Any advice?
I'm looking to write a class test for my batch. Any advice?
global class FA_BA_UpdateAccounts implements Database.Batchable<sObject>{ global Database.QueryLocator start(Database.BatchableContext info){ //Requeter seulement les comptes qui ont au moins une commande avec le Status 'Ordered' return Database.getQueryLocator('SELECT Id FROM Account WHERE Id In =: (SELECT AccountId FROM Order WHERE Status = \'Ordered\' AND Status = \'Activated\' )'); //new instance of accountQuery //FA_QR_Account accountQuery = new FA_QR_Account(); } global void execute(Database.BatchableContext info, List<Account> scope){ FA_QR_Order orderQuery = new FA_QR_Order(); FA_SRV_Account accountService = new FA_SRV_Account(); //Call the method getOrders list<Order> listOrders = orderQuery.getOrders(); for(integer i=0; i < scope.size(); i++){ Account myAccount = scope[i]; myAccount.Chiffre_d_affaire__c = 0; for(integer j=0; j < listOrders.size(); j++){ if(listOrders[j].AccountId == myAccount.Id){ myAccount.Chiffre_d_affaire__c = myAccount.Chiffre_d_affaire__c + listOrders[j].TotalAmount; } } } accountService.updateAccount(scope); } global void finish(Database.BatchableContext info){ } }
https://jayakrishnasfdc.wordpress.com/2021/01/02/apex-test-class-for-batch-apex/
https://salesforce.stackexchange.com/questions/244788/how-do-i-write-an-apex-unit-test
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
If you face any specific issue while attempting do post that here.
Thanks!
Thanks for your reply. I've attempted some issues with the order status:
= >first error: FAILED_ACTIVATION, Choose a valid status and save your changes. For a new or cloned order, choose Draft. An Activated order's status can't be edited.: [Status]
I'm looking for setting up my test with the status "Ordered" :
Try Below Test Class Please Mark It As Best Answer If It Helps
Thank You!