You need to sign in to do that
Don't have an account?
Aurora Ganguly 10
test class for DeleteWithCheckboxController
Hi All,
Can anyone help me out in writing this test class for this apex class.
Aurora.
Can anyone help me out in writing this test class for this apex class.
public with sharing class DeleteWithCheckboxController { @AuraEnabled public static list < contact > fetchContact() { list < contact > returnConList = new List < contact > (); List < contact > lstCon = [SELECT Name, firstName, LastName, Department, MobilePhone From contact LIMIT 50]; // play for loop on lstCon and add each contact to returnConList List. for (contact c: lstCon) { returnConList.add(c); } // return the List of contacts return returnConList; } @AuraEnabled public static List < String > deleteRecords(List < String > lstRecordId) { // for store Error Messages List < String > oErrorMsg = new List < String > (); // Query Records for delete where id in lstRecordId [which is pass from client side controller] List < contact > lstDeleteRec = [select Id from contact where id IN: lstRecordId]; // delte contact list with Database.DeleteResult[] database class. // It deletes some queried contacts using <samp class="codeph apex_code">Database.<span class="statement">delete</span></samp> // with a false second parameter to allow partial processing of records on failure. // Next, it iterates through the results to determine whether the operation was successful or not // for each record. and check if delete contact successful so print msg on debug, // else add error message to oErrorMsg List and return the list Database.DeleteResult[] DR_Dels = Database.delete(lstDeleteRec, false); // Iterate through each returned result for (Database.DeleteResult dr: DR_Dels) { if (dr.isSuccess()) { system.debug('successful delete contact'); // Operation was successful } else { // Operation failed, so get all errors oErrorMsg.add(''); for (Database.Error err: dr.getErrors()) { // add Error message to oErrorMsg list and return the list oErrorMsg.add(err.getStatusCode() + ': ' + err.getMessage()); } } } return oErrorMsg; } }Looking for your help.
Aurora.
Hi Aurora,
Please try this piece of code. hope it will help you.
If this code helps you, Please mark it as best to close this Question.
Regards,
Suraj
I will check n let u know ..
Thanks for the help