+ Start a Discussion
ruchika Nayyarruchika Nayyar 

invalid field student

public class studenttrigger1 
{
    
    public void onbeforeinsert(list<myruchika__Student__c>TriggerNew)
    {
        createStatusofTeacher(TriggerNew);
    }
    void  createStatusofTeacher(list<myruchika__Student__c>TriggerNew)
    {
    set<ID> settech= New set<ID>();
    for(student__c objS:TriggerNew)
    {
     if(objS.myruchika__Teacher__c!=null)
     {
         settech.add(objS.myruchika__Teacher__c);
     }
    }
 map<ID,myruchika__Teacher__c> mapteach=new map<ID,myruchika__Teacher__c>([select ID, myruchika__statusofteacher__c from myruchika__Teacher__c where ID in:settech]);
     for(student__c objT:Triggernew)
     {
       If (objT.student__c!=null && mapstudent__c.get(objT.myruchika__Teacher__c)!=null)
           {
               teacher__c obj= mapteach.get(objT.myruchika__Teacher__c);
           
         if(obj.myruchika__statusofteacher__c==false)
         {
             objT.adderror('Teacher must be active to create student');
         }
          }
   }   
    
    }
            }



 
Ajay Nagar 7Ajay Nagar 7
If student__c is not a field on student obejct then remove "objT.student__c!=null" condition from if statement.