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

Criteria based rollup in trigger
I have an object, Object1__c, that has a lookup relationship to the account object. Also on Object1__c is a picklist field that is used to indicate the outcome of a call (declined, no answer, etc.).
On the account object I have then placed a number of custom fields that will be used to house the count of each outcome value for Object1 records related to that account.
In my trigger on Object1, I am able to populate the appropriate custom field on the account object using this code as an example:
Is there a way to do this with one query? I thought something along the lines of AggregateResult might be appropriate, but am having trouble then ensuring that I pull the correct values based on the individual account Ids found in my set of account Ids (acctSet).
Any help would be appreciated.
On the account object I have then placed a number of custom fields that will be used to house the count of each outcome value for Object1 records related to that account.
In my trigger on Object1, I am able to populate the appropriate custom field on the account object using this code as an example:
List<Account> aToUpdate = new List<Account>(); for(Account a : [SELECT Id, Declined__c, (SELECT Id, Outcome__c FROM Object1s__r WHERE Disposition__c = 'Declined') FROM Account WHERE Id IN :acctSet]){ a.Declined__c = a.Object1s__r.size(); aToUpdate.add(a); } Update aToUpdate;...but doing it this way doesn't feel right as I'd then have a separate SOQL query for each outcome value.
Is there a way to do this with one query? I thought something along the lines of AggregateResult might be appropriate, but am having trouble then ensuring that I pull the correct values based on the individual account Ids found in my set of account Ids (acctSet).
Any help would be appreciated.
I could be misreading this, so I'm sorry if I am.
This code only has 1 query. The query won't run through each iteration, just once and then it will loop through the list that it returns.