You need to sign in to do that
Don't have an account?
Devendra Hirulkar 3
trigger to copy child field data to parent field data (workflow also if it possible by workflow)
trigger to copy child field data to parent field data
like i have copy data from student(child) to class (parent) but by matching the name of both child and parent
if the name of the both child and parent are match then only save the data like if the name of both child and parent are match then when we save rollno on student it compare name if match then it automticlly stored on class
thanks
like i have copy data from student(child) to class (parent) but by matching the name of both child and parent
if the name of the both child and parent are match then only save the data like if the name of both child and parent are match then when we save rollno on student it compare name if match then it automticlly stored on class
thanks
trigger CopyChildtoParent on Child (after insert,after update)
{
Child con = [Select #Fieldyouwishtocopy from Child where ID=:trigger.id[;
// SOQL to get the exact account with matching name as child
Parent par : [select Id, #Fieldyouwishtoupdate from Parent where Parent.name in :Trigger.new.Name]
par.#Fieldyouwishtoupdate = con.#Fieldyouwishtocopy
update con;
}
reference:
http://stackoverflow.com/questions/21738345/trigger-to-update-account-filed-when-a-corresponding-contact-field-is-updated-i
Hope this helps !!
in the above sonam trigger there is one error has occur
(unexpected token: ':' at line 6 )here is trigger
trigger CopyChildtoParent on class__c (after insert) {
Child con = [Select Roll_No__c from class__c where ID=:trigger.id];
// SOQL to get the exact account with matching name as child
Parent par : [select Id, Roll_No__c from Student__c where Student__c.name in :Trigger.new.Name]
par.Roll_No__c = con.Roll_No__c
update con;
thanks
Devendra
Parent par : [select Id, Roll_No__c from Student__c where Student__c.name in :Trigger.new.Name](here the line error)
please tell me what goes wrong about the trigger
the trigger is correct to the map but u say the(
and see if the map contains the same name, if yes then put the lookup value as the matching id from the map.
) i dont undestand what to do to match and put them
trigger dataupdate on class__c (before insert, before update)
{
//create reference table for lookup value
Map<String, Integer> stdMap = new Map<String, Integer>();
//build reference table for VAT rates
for (Student__c std : [SELECT Name, Roll_No__c FROM Student__c])
stdMap.put(std.Name, std.Roll_No__c);
//update Student__c with VAT rate
for (Student__c stud : trigger.new)
{
Integer roll = stdMap.get(stud.Name);
stud.Student__c = roll;
}
}
thanks
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();
}
}
Create countfiled in parent ,
add belowtrigger in chield .
Regards,
harish.