You need to sign in to do that
Don't have an account?
Cameron Houser
Bug with process Builder, wont total sum of fields on parent object unless a new record is created on child object
Bug with process Builder, wont total sum of fields on parent object unless a new record is created on child object.
I am tying to sum totals of records with a specific date onto a Account Field from an Order object records. My apex works, the only catch is I have to create 2 order records inorder to see the 1st records amount added to the field on the Account object.
Any help would be greatly appriciated.
I am tying to sum totals of records with a specific date onto a Account Field from an Order object records. My apex works, the only catch is I have to create 2 order records inorder to see the 1st records amount added to the field on the Account object.
Any help would be greatly appriciated.
All Answers
My Apex Class:
public class SumOrdersOnAccountforNextYear {
@InvocableMethod
public static void SumAccountOrders(List<Id> AccountIds)
{
for(Id record: AccountIds) {
Account updateAccount = new Account(Id = record);
updateAccount.Last_Season_Sales__c = null;
updateAccount.Current_Season_Total_Orders__c = null;
updateAccount.Total_Sales_2_Years_Ago__c = null;
for(AggregateResult result: [SELECT SUM(TotalAmount) Amt, AccountId Id FROM Order WHERE AccountId = :record AND (EffectiveDate >= :date.parse('07/01/2017')) AND (EffectiveDate <= :date.parse('06/30/2018')) GROUP BY AccountId]) {
updateAccount.Last_Season_Sales__c = (Decimal)result.get('Amt');
}
for(AggregateResult result: [SELECT SUM(TotalAmount) Amt, AccountId Id FROM Order WHERE AccountId = :record AND (EffectiveDate >= :date.parse('07/01/2018')) AND (EffectiveDate <= :date.parse('06/30/2019')) GROUP BY AccountId]) {
updateAccount.Current_Season_Total_Orders__c = (Decimal)result.get('Amt');
}
for(AggregateResult result: [SELECT SUM(TotalAmount) Amt, AccountId Id FROM Order WHERE AccountId = :record AND (EffectiveDate >= :date.parse('07/01/2016')) AND (EffectiveDate <= :date.parse('06/30/2017')) GROUP BY AccountId]) {
updateAccount.Total_Sales_2_Years_Ago__c = (Decimal)result.get('Amt');
}
update updateAccount;
}
}
}