You need to sign in to do that
Don't have an account?

Account Trigger for Cross Object Roll Up
Can anyone help explain why my trigger wont fire? I am really stumpped. Any help is much appreciated.
trigger ConsultingAUMRS on Account (before update, after update) { system.debug ('Raul');{
Account Rollup = new Account();
for (AggregateResult ar:[select sum(AUM__C)total from Investment__c Where Consultant__c !=null])
{
system.debug('Hello1');
Rollup.Total_Consultant_AUM__c = (decimal)ar.get('total');
system.debug((decimal)ar.get('total'));
}
}
}
trigger ConsultingAUMRS on Account (before update, after update) { system.debug ('Raul');{
Account Rollup = new Account();
for (AggregateResult ar:[select sum(AUM__C)total from Investment__c Where Consultant__c !=null])
{
system.debug('Hello1');
Rollup.Total_Consultant_AUM__c = (decimal)ar.get('total');
system.debug((decimal)ar.get('total'));
}
}
}
trigger ConsultingAUMRS on Account (before update)
{
for (Account ac :Trigger.new)
{
string accountID;
accountID = ac.Name;
system.debug(accountID);
}
//system.debug(accountID);
for (Account a :Trigger.new)
{
//String accid = a.Name;
for (AggregateResult ar:[select sum(AUM__C)total from Investment__c Where Consultant__c !=null and Organization__c =: accountID]);
{
system.debug('Hello1');
a.Total_Consultant_AUM__c = (decimal)ar.get('total');
system.debug((decimal)ar.get('total'));
}
}
}
Updated Code
trigger ConsultingAUMRS on Account (before update)
{
for (Account ac :Trigger.new)
{
string accountID;
accountID = ac.Name;
system.debug(accountID);
}
system.debug(accountID);
/*for (Account a :Trigger.new)
{
//String accid = a.Name;
for (AggregateResult ar:[select sum(AUM__C)total from Investment__c Where Consultant__c !=null and Organization__c =: accountID]);
{
system.debug('Hello1');
a.Total_Consultant_AUM__c = (decimal)ar.get('total');
system.debug((decimal)ar.get('total'));
}
}*/
}
{
for (Account ac :Trigger.new)
{
string accountID;
accountID = ac.ID;
//system.debug(accountID);
}
system.debug(accountID);
for (Account a :Trigger.new)
{
//String accid = a.Name;
for (AggregateResult ar:[select sum(AUM__C)total from Investment__c Where Consultant__c !=null and Organization__c =: accountID]);
{
system.debug('Hello1');
a.Total_Consultant_AUM__c = (decimal)ar.get('total');
system.debug((decimal)ar.get('total'));
}
}
}
select sum(AUM__C)total from Investment__c Where Consultant__c !=null and Organization__c = '<sample account id>';
trigger ConsultingAUMRS on Account (before update)
{
System.debug('++++++++++++ before update trigger +++++++');
for (Account ac :Trigger.new)
{
System.debug('++++++++ found account: ' + ac.ID);
AggregateResult ar = [select sum(AUM__C)total from Investment__c Where Consultant__c !=null and Account_ID__c =: ac.Id];
//System.debug('++++++++ total (double) ' + (Double) ar.get('total');
//System.debug('++++++++ total (decimal)' + (Decimal) ar.get('total');
ac.Total_Consultant_AUM__c = (Double) ar.get('total');
} // for (Account ac :Trigger.new)
}