• Santhosh Kon 5
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 2
    Replies
trigger studentupdate123 on Teacher__c (after update) {
list<Student__c> childquery=new list<student__c>();
list<Student__c> childupdatelist=new list<student__c>();
for(Teacher__c acc:[select id,name,City__c,(select id ,name,City__c from Students__r) from Teacher__c])
{
if(acc.Students__r.size()>0 &&acc.Students__r.size()!=null){
childquery.add(acc.Students__r);
}

}
for(Teacher__c ad:Trigger.new)
{

for(Student__c c:childquery)
{
c.City__c=ad.City__c;
childupdatelist.add(c);
}
}
if(childupdatelist.size()>0 && childupdatelist.size()!=null){
update childupdatelist;
}
}
trigger studentcount1 on Student__c (after insert,after update,after delete,after  undelete) {
    set<ID> parentID=new set<ID>();
    List<Teacher__c> ParentQueryList=new list<Teacher__c>();
    List<Teacher__c> ParentToupdate=new list<Teacher__c>();
    If(Trigger.isinsert|| Trigger.isupdate||Trigger.isundelete)
    {
    for(student__c acc:Trigger.new)
    {
        if(acc.subject__r.id!=null)
        {
        parentID.add(acc.subject__r.id);
        }
    }
    }
    If(Trigger.isdelete){
        for(student__c acc:Trigger.old)
        {
           if(acc.subject__r.id!=null)
        {
        parentID.add(acc.subject__r.id);
        } 
            
        }
    }
      if(parentID.size()>0)
      
    ParentQueryList=[select id,name,childcount__c,(select id,name,subject__c from students__r) from Teacher__c where ID in :parentID];
   system.debug('ParentQueryList--->'+ParentQueryList);
   
    for(Teacher__c tc:ParentQueryList)
    {
        tc.childcount__c=tc.students__r.size();
        ParentToupdate.add(tc);
    }
    if(ParentToupdate.size()>0)
    {
    update ParentToupdate;
    }
  
    
        
         
        
        
 

}
trigger studentupdate123 on Teacher__c (after update) {
list<Student__c> childquery=new list<student__c>();
list<Student__c> childupdatelist=new list<student__c>();
for(Teacher__c acc:[select id,name,City__c,(select id ,name,City__c from Students__r) from Teacher__c])
{
if(acc.Students__r.size()>0 &&acc.Students__r.size()!=null){
childquery.add(acc.Students__r);
}

}
for(Teacher__c ad:Trigger.new)
{

for(Student__c c:childquery)
{
c.City__c=ad.City__c;
childupdatelist.add(c);
}
}
if(childupdatelist.size()>0 && childupdatelist.size()!=null){
update childupdatelist;
}
}