You need to sign in to do that
Don't have an account?
Devendra Hirulkar 3
copy child field data to parent field using trigger have two object child(class) and parent(student)
who to copy child field data to parent field using triggeri have two object child(class) and parent(student)
student class
----------------------------
name name
address student(lookup)
rollno rollno
------------------------------
in above to obj if student name and class name will match then it copy rollno from class and put into student
please tell me how to get this
thanks,
devendra
student class
----------------------------
name name
address student(lookup)
rollno rollno
------------------------------
in above to obj if student name and class name will match then it copy rollno from class and put into student
please tell me how to get this
thanks,
devendra
You can try the below code as well..
trigger UpdateRollNo on Class__c (before insert,before update) {
Map<Id,Student__c> studMap = new Map<Id,Student__c>();
Set<Id> Ids = new Set<Id>();
for(Class__c c: Trigger.new)
{
Ids.add(c.Student_Name__c);
}
Map<id,Student__c> studmap2 = new Map<id,Student__c>([Select Id,Name,Student_Roll_Number__c From Student__c where Id IN : Ids]);
for(Class__c c1 : Trigger.new)
{
Student__c st = studMap2.get(c1.Student_Name__c);
if(st.Student_Roll_Number__c == '')
{
st.Student_Roll_Number__c = c1.Student_Roll_No__c;
studMap.put(st.id,st);
}
}
if(!studmap.isEmpty())
{
update studMap.values();
}
}