You need to sign in to do that
Don't have an account?
Aditi Mohanty 5
i need test class for this. I am not getting above 75% coverage
global class Batch_AddConToAcc implements Database.Batchable <sObject> { List<contact> lstCon = new List<Contact>(); String query = 'SELECT Id, Name FROM Account WHERE checkacc__c = True'; global Database.QueryLocator start(Database.BatchableContext bc) { return Database.getQueryLocator(query); } global void execute(Database.BatchableContext bc,List<Account> batch) { List<Account> acnt=new List<Account>(); for (Account a : batch) { if(a.checkacc__c = True){ Contact c = new Contact(); c.LastName = a.Name; c.AccountId = a.Id; lstCon.add(c); } INSERT lstCon; } for (Account a : batch){ a.checkacc__c = False; acnt.add(a); } update acnt; } global void finish(Database.BatchableContext bc) { AsyncApexJob ajob = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email FROM AsyncApexJob WHERE Id = :bc.getJobId()]; if(ajob.Status=='Completed'){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {ajob.CreatedBy.Email}; mail.setToAddresses(toAddresses); mail.setSubject('Apex Sharing Recalculation ' + ajob.Status); mail.setPlainTextBody ('The batch Apex job processed ' + ajob.TotalJobItems + ' batches status '+ajob.Status ); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } else{ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {ajob.CreatedBy.Email}; mail.setToAddresses(toAddresses); mail.setSubject('Apex Sharing Recalculation ' + ajob.Status); mail.setPlainTextBody ('The batch Apex job processed ' + ajob.TotalJobItems + ' batches with '+ ajob.NumberOfErrors + ' failures.'); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } }
Can you post the test class code you have written so far and highlight the lines of code (from class in bold)that need coverage so the community can help.
If you are looking for writing test class from scratch, the below post should help you get started
Code Coverage Best Practices
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_code_coverage_best_pract.htm
Checking Code Coverage
https://help.salesforce.com/articleView?id=code_dev_console_tests_coverage.htm&type=5
Deployment related code coverage issues
https://help.salesforce.com/articleView?id=000335222&type=1&mode=1
https://salesforce.stackexchange.com/questions/148894/help-required-to-get-full-code-covered-in-test-class
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
If this information helps, please mark this answer as best.Thanks
add acc.checkacc__c = True while inserting the Account in test class.
Thanks,
Maharajan.C