function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
harsh shuklaharsh shukla 

Attendance Creation on Student Record

Hi, 

I want to create an attendance record whenever any sudent record is created, There should be 12 records for attendance from Jan-Dec.

 Below is my code but it's not working. Please help

Apex Class---------------
public class AttendanceClass {
        public static void AttendanceCreation(List<Student1__c>StudentLists){
        List<Attendance__c>AttendanceList = new List<Attendance__c>();
        List<String>MonthsList = new List<String>();
        MonthsList.add('Janauary');
        MonthsList.add('February');
        MonthsList.add('March');
        MonthsList.add('April');
        MonthsList.add('May');
        MonthsList.add('June');
        MonthsList.add('July');
        MonthsList.add('August');
        MonthsList.add('September');
        MonthsList.add('October');
        MonthsList.add('November');
        MonthsList.add('December');
        
        for(Student1__c s : StudentLists ){
            for(integer i=0; i<12; i=i+1){
                Attendance__c VarA = new Attendance__c();
                VarA.Name = MonthsList.get(i);
                VarA.Days_Present__c = 0;
                VarA.Student_ID__c = s.Roll_Number__c;
                AttendanceList.add(VarA);
            }
        }
        insert AttendanceList;
        
        
        
    }
}

Apex Triggers----------
trigger attendancetrigger1 on Student1__c (after insert) {
    
    if(trigger.isAfter == true && trigger.isInsert == true){
        AttendanceClass.AttendanceCreation(trigger.new);
    }
      
}
SUCHARITA MONDALSUCHARITA MONDAL
Hi Harsh,
What's issue that you are getting.  I tried the above code and it's working fine. 

Thanks,
Sucharita
James HamanJames Haman
Yeah, It works well for me also.
Jocelyn SanchezJocelyn Sanchez
I also want to create an attendance record because this is regarding my project and for that, I am searching for useful information online. I am glad I have found your post. I was reading a review for Edubirdie online on https://edubirdie.net/blog/is-edubirdie-legal-or-cheating and while reading, I have found your post. I am looking for it because I was searching for an essay writing service online and found them. And your code is working well for me too, I don't know why you facing a problem with this.