+ Start a Discussion
TamaraUTamaraU 

Trigger: update child object field with parent's value (it updates via formula)

I'm new with triggers and am having trouble with making one work.

 

I have a child custom object called "Actividad" which has a formula field called "Actor Principal Indicador" that gets updated from a field in its' parent object "Indicador".

"Actividad" is also parent for the object "Entidad participante".

 

What I want my trigger to do is to update a field ("Actor Principal Indicador" - yes, it has the same name as the field in the other object) in "Entidad participante" getting the value from its parent's field "Actor Principal Indicador" (which originally gets its value from the "Indicador" objetc)

 

Is this possible?

Any help would be appreciated!

 

This is what I have so far:

 

trigger ActualizarActorPrincipal on Actividad__c (after update, after insert) {
   Set<ID> IDActividad = new Set<ID>();
    for(Actividad__c A: Trigger.new){
        List<Actividad__c> ActividadActualizada = [SELECT Id, Actor_principal_indicador__c, (Select Id, Actor_principal_indicador__c from Organizaciones_participantes__r)  FROM Actividad__c WHERE Id in :IDActividad];
        List<Entidad_participante__c> EntParticipActualizar = new List<Entidad_participante__c>();
    for (Actividad__c AA: ActividadActualizada){
        for(Entidad_participante__c EP : AA.Organizaciones_participantes__r){  if(EP.Actor_principal_indicador__c == null)
            EP.Actor_principal_indicador__c = AA.Actor_principal_indicador__c;
       EntParticipActualizar.add(EP);
                }
        
   
            update EntParticipActualizar;
       }
    }}

Best Answer chosen by Admin (Salesforce Developers) 
willardwillard
Why don't you just create a formula field on "Entidad participante" to get the value on Actividad."Actor Principal Indicador"?

All Answers

willardwillard
Why don't you just create a formula field on "Entidad participante" to get the value on Actividad."Actor Principal Indicador"?
This was selected as the best answer
TamaraUTamaraU

True. What I forgot to say is that I wanted to use a resume field using this "actor principal indocador" field as a filter, and as far as I could test, it won't let me use a formula for a resume field. am I right?

TamaraUTamaraU

Hey, I finally got to do it via workflow and formulas.

Thanks!