You need to sign in to do that
Don't have an account?
Nishit Mistryyy
Writing a test class for the apex class that is fetching data from the salesforce org.
Hello,
I have a apex class defined as ContactListController, this class basically gets the list of contacts from my salesforce developer org. I want to write the test class for it.
The code is:
public class ContactListController {
@AuraEnabled
public static List<Contact> getContactList(List<Id> accountIds) {
// Getting the list of contacts from where Id is in accountIds
List<Contact> contactList = [SELECT Id, Name, Email FROM Contact WHERE AccountId in :accountIds];
// Returning the contact list
return contactList;
}
}
I have a apex class defined as ContactListController, this class basically gets the list of contacts from my salesforce developer org. I want to write the test class for it.
The code is:
public class ContactListController {
@AuraEnabled
public static List<Contact> getContactList(List<Id> accountIds) {
// Getting the list of contacts from where Id is in accountIds
List<Contact> contactList = [SELECT Id, Name, Email FROM Contact WHERE AccountId in :accountIds];
// Returning the contact list
return contactList;
}
}
Can you try the below test class. it should give you 100% coverage.
While inserting Account and Contact make sure all the required fields were defined below.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,