function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PadtalluriPadtalluri 

Apex trigger not firing - update fields from custom object to Account Object

trigger AlertTrigger on Alert__c (after update) {

System.debug('@@@@@@@@@@@');

    List<Account> acctlist = new List<Account>();
    Set<Id> acid = new Set<Id>();
       
       for(Alert__c ab:Trigger.New) {
           
           acid.add(ab.Account__c);
           
           system.debug('&&&&&&&&'+acid); 
       }
       
       Map<Id,Account> acct = new Map<Id,Account>([Select Id,Effective_Date__c,Region__c from Account where Id in :acid]);
           Set<Account> a = new Set<Account>();

    
          for(Alert__c b : Trigger.new){
     
              if(acct.containsKey(b.Account__c)) {
                   If(b.Type__c == 'New Client') 
        
                   {
                     
                      Account upd = acct.get(b.Account__c);
                        
                      If(upd.Relationship__c == 'Client' || upd.Relationship__c == 'Broker') 
                        { 

                          upd.Effective_Date__c = b.Effective_Date__c;
                          upd.Aetna_Region__c = b.Region__c;
                          a.add(upd);
            
                        }   
                  }

      }
   }
   
   
     acctlist.addAll(a);
    
     update acctlist;

}
Best Answer chosen by Padtalluri
KevinPKevinP
Padtalluri, 

Your trigger is setup as an *after update*, not an after INSERT. if you want to be able to see the changes after creating the initial alert__C object, you'll need to modify the first line of your trigger to read:
 
trigger AlertTrigger on Alert__c (after update, after insert) {

 

All Answers

KevinPKevinP
what's your test look like for this ? I ask, because I want to see what you're doing to fire this trigger?
PadtalluriPadtalluri
Hi Kevin,

I did not write the test class yet, I am testing through the UI.

Created a new Alert__c record and populated the fields effective date and regionand after saving the record, the account fields are not getting populated with alert__c fields values. 

the relationship is a look up.
KevinPKevinP
Padtalluri, 

Your trigger is setup as an *after update*, not an after INSERT. if you want to be able to see the changes after creating the initial alert__C object, you'll need to modify the first line of your trigger to read:
 
trigger AlertTrigger on Alert__c (after update, after insert) {

 
This was selected as the best answer
PadtalluriPadtalluri
Thank you Kevin, do not know What I was thinking :)