Skip to main content
Agnibha Chakrabarti (cognizant) a posé une question dans #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 réponses
  1. 17 oct. 2019, 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