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

need help adding conditional filtering to roll-up trigger
I am looking for a way to add conditional filtering to the "ctx.add( " portions below.
trigger OppRollup on Opportunity (after insert, after update, after delete, after undelete) { // modified objects whose parent records should be updated Opportunity[] objects = null; if (Trigger.isDelete) { objects = Trigger.old; } else { /* Handle any filtering required, specially on Trigger.isUpdate event. If the rolled up fields are not changed, then please make sure you skip the rollup operation. We are not adding that for sake of similicity of this illustration. */ objects = Trigger.new; } /* First step is to create a context for LREngine, by specifying parent and child objects and lookup relationship field name */ LREngine.Context ctx = new LREngine.Context(Account.SobjectType, // parent object Opportunity.SobjectType, // child object Schema.SObjectType.Opportunity.fields.AccountId // relationship field name ); /* Next, one can add multiple rollup fields on the above relationship. Here specify 1. The field to aggregate in child object 2. The field to which aggregated value will be saved in master/parent object 3. The aggregate operation to be done i.e. SUM, AVG, COUNT, MIN/MAX */ ctx.add( new LREngine.RollupSummaryField( Schema.SObjectType.Account.fields.AnnualRevenue, Schema.SObjectType.Opportunity.fields.Amount, LREngine.RollupOperation.Sum )); ctx.add( new LREngine.RollupSummaryField( Schema.SObjectType.Account.fields.SLAExpirationDate__c, Schema.SObjectType.Opportunity.fields.CloseDate, LREngine.RollupOperation.Max )); /* Calling rollup method returns in memory master objects with aggregated values in them. Please note these master records are not persisted back, so that client gets a chance to post process them after rollup */ Sobject[] masters = LREngine.rollUp(ctx, objects); // Persiste the changes in master update masters; }
need more info, did not undertand what is the actual requirement.
You can use If statement in APEX to put filters/validate data before adding into collection
Ultimately i will need about 12 more roll-up fields (at max already), all looking at records related to parent object. each is a sum of a certain record type, with one field that is a picklist.
each roll-up will count the number of records for that record type with a certain value from the picklist
I tried an if statement, but it could not do what I wanted.
I tried to modity the code in this portion: but was not successful - one example would be to get a rollup of related opps where the stage was prosepecting, one where stage was qualified, etc. - hope this makes sense
Hello, this is the class for this trigger:
the recommendation for adding conditional filtering to the trigger was as follows:
the error I got when I tried to add something like this was that "Variable does not exist: detailRecords"