You need to sign in to do that
Don't have an account?
Menachem Ejdelman
trigger to update a number field automatically when a formula field value changes
Hello,
I am trying to create a trigger that makes a number field automatically be populated with data that is in a formula field whenever the formula field is changed. (regardless of whether a user edited the record or not).
The code of the formula field (Parent_number_reached__c) is as follows: Parent_Object__r.Number_Reached__c
The Number field is called Parent_number_reached_local__c
I want Parent_number_reached_local__c to have the data be synchronized with Parent_number_reached__c, so that whenever Parent_number_reached__c is changed, change Parent_number_reached_local__c to the same value.
I am told that this is a relatively simple Trigger to write. Please send me such a code.
Thank you,
Menachem
I am trying to create a trigger that makes a number field automatically be populated with data that is in a formula field whenever the formula field is changed. (regardless of whether a user edited the record or not).
The code of the formula field (Parent_number_reached__c) is as follows: Parent_Object__r.Number_Reached__c
The Number field is called Parent_number_reached_local__c
I want Parent_number_reached_local__c to have the data be synchronized with Parent_number_reached__c, so that whenever Parent_number_reached__c is changed, change Parent_number_reached_local__c to the same value.
I am told that this is a relatively simple Trigger to write. Please send me such a code.
Thank you,
Menachem
Hi,
Write trigger on parent object to populate same value in child as well.
please refer below,
trigger testTrigger on Parent_Object__c (after update){
map<id,Parent_Object__c> parentids =new map<id,Parent_Object__c>();
for(Parent_Object__c c :trigger.new){
parentids.put(c.id,c);
}
List<Childrecords> lstchilds =[select id,Parent_number_reached_local__c from child where parentid in :parentids.keyset()];
for(Childrecords cc : lstchilds ){
cc.Number field is called Parent_number_reached_local__c = parentids.get(parent ID).parentfield;
}
update lstchilds;
}
Apologies, My mistake..copied some extra text from above.Please modify this for loop.
for(Childrecords cc : lstchilds ){
cc.Parent_number_reached_local__c = parentids.get(parent ID).Number_Reached__c;
}
Please ping me in Skype at 'raviteja.epuri' in case of any query.or drop me mail at raviteja8899@gmail.com. Happy to Help :)