You need to sign in to do that
Don't have an account?
Padtalluri
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;
}
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;
}
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:
All Answers
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.
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: