+ Start a Discussion
Tanvi KakkarTanvi Kakkar 

trigger for field update on unrelated objects

I have two objects parent__c and Teacher__c . There is no relationship between them .no materdetail no lookup . 
Parent fields: name(text )
, email (email)
, teacher_expertise (text)
Teacher Name (text)
Teacher fields :
- name (text)
expertise (picklist) 
I would like to update teacher field on parent objects :
Please help . Urgent
If there is no relationship between that object, then what is the matching criteria to identify and update record on parent object?
Rahul Sangwan7341Rahul Sangwan7341

Hi Tanvi,

Write a trigger on Teacher object and in trigger check the parent record which matches with Teacher record based on the field which you are matching and then update the Parent record. Code will be something like this:

List<Teacher__c> t=trigger.new;

List<Parent__c> p=[Select Name,Teacher_expertise__c from Teacher where Teacher_expertise__c IN : t.expertise ];
List<Parent__c> pt=new List<Parent__c>();
for(Teacher__c tc:t){
   for(Parent__c par:p){
   if(par.Teacher_expertise__c ==tc.expertise ){
update p;

Change the fields according to you.

Please mark this as Best Answer if it helps you.