You need to sign in to do that
Don't have an account?
Renuka Sharma
how to write test class for apex code
hey Guys
i need a small help regarding a test classes. Basically i am trying to design a test class for account and contact, in my case Account is Renamed as (Courses) and Contact is Renamed as (Students), and i have 2 custom objects Classes(Class__c) and Attendancess (Attendancess__c)
how do i design a test class for below apex class
i need a small help regarding a test classes. Basically i am trying to design a test class for account and contact, in my case Account is Renamed as (Courses) and Contact is Renamed as (Students), and i have 2 custom objects Classes(Class__c) and Attendancess (Attendancess__c)
how do i design a test class for below apex class
public class UpdateUsingCheckboxC { @AuraEnabled public static List <Contact> fetchContact(string key) { system.debug('classname'+key); Class__c cls = [select id,Courses__r.name from Class__c where id=:key]; string classname = cls.Courses__r.name; system.debug('classname'+classname); return [SELECT Id, Name,Account.Name,FirstName,LastName,Check_for_Attendance__c,Check_for_Absentee__c FROM Contact where (Check_for_Attendance__c=false AND Check_for_Absentee__c=false) AND Account.Name =:classname]; } @AuraEnabled public static void updateRecord(List <String> lstRecordId,string key) { List<Contact> lstUpdate = new List<Contact>(); List<Attendancess__c> listAttendnce = new List<Attendancess__c>(); Class__c cls = [select id,Courses__r.name from Class__c where id=:key]; if(cls.Id !=null){ for(Contact con : [SELECT Id,AccountId, Name,Phone,FirstName,LastName,Check_for_Attendance__c,Check_for_Absentee__c FROM Contact WHERE Id IN : lstRecordId]){ con.Check_for_Attendance__c = true; con.Check_for_Absentee__c = false; lstUpdate.add(con); Attendancess__c attandenc = new Attendancess__c(); attandenc.Class__c = cls.Id; attandenc.Student_Attended__c = true; attandenc.Name = con.Name; attandenc.Created_Date_Time__c = system.now(); listAttendnce.add(attandenc); system.debug('listAttendnce'+listAttendnce); } if(lstUpdate.size() > 0){ update lstUpdate; } if(listAttendnce.size() > 0){ insert listAttendnce; } } } @AuraEnabled public static void updateSecondRecord(List <String> secondRecordId,string key) { system.debug('key1'+key); system.debug('secondRecordId '+secondRecordId); List<Contact> lstUpdate = new List<Contact>(); List<Attendancess__c> listAttendnce = new List<Attendancess__c>(); if(key !=null){ Class__c cls = [select id,Courses__r.name from Class__c where id=:key]; for(Contact con : [SELECT Id,AccountId, Name,Phone,FirstName,LastName,Check_for_Attendance__c,Check_for_Absentee__c FROM Contact WHERE Id IN : secondRecordId]){ con.Check_for_Absentee__c = true; con.Check_for_Attendance__c = false; lstUpdate.add(con); Attendancess__c attandenc = new Attendancess__c(); attandenc.Class__c = cls.Id; attandenc.Student_Attended__c = false; attandenc.Name = con.Name; attandenc.Created_Date_Time__c = system.now(); listAttendnce.add(attandenc); system.debug('listAttendnce'+listAttendnce); } if(lstUpdate.size() > 0){ update lstUpdate; } if(listAttendnce.size() > 0){ insert listAttendnce; } } } }
Try this test class...
Hope this will help...
All Answers
Try this test class...
Hope this will help...
i tried your code and made few changes and it worked perfectly