Skip to main content
Agnibha Chakrabarti (cognizant) 님이 #Apex에 질문했습니다
hi,

my requirement is

 After the batch is over, Teacher will mark the batch as complete. Then the course will be moved from Requested Courses to Completed Coursed for all the students of the batch. Before marking a batch as complete, the teacher can remove any student from the batch. This will not be possible after the batch is completed.

Relationship:

Trigger in junction objectim trying to access the students whose batch is completed(batch has a checkbox mark as complete or not)

trigger Batch on Batch__c (before insert,after update) {

List<String> b= new List<String>();

for(Batch__c p: Trigger.new){

b.add(p.Name);

}

List<Student__c> c=new List<Student__c>([select Student__r.Name from Student_Batch_Junction__c where Batch__r.Name in :b]);

}

I tried to access student in this way..it is showing error
답변 6개
  1. 2019년 10월 17일 오후 12:38
    Hi Agnibha,

    Please check below code:

    trigger Batch on Batch__c (before insert,after update) {

        List<String> b= new List<String>();  

         for(Batch__c p: Trigger.new){

             b.add(p.Name);

         }

        List<Student_Batch_Junction__c > c=new List<Student_Batch_Junction__c>([select Student__r.Name from Student_Batch_Junction__c where Batch__r.Name in :b]);   

    }

    I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

    Thanks and Regards,

    Deepali Kulshrestha

    www.kdeepali.com