You need to sign in to do that
Don't have an account?
TC Admin
error on trigger - execution of AfterUpdate caused by: System.ListException:
Hi All,
I have created the below code for a trigger that once an opportuntiylineitem is added, edited, deleted or undelted it SUM() the total of all product ids on opportuntilineitems as a particular status.
However I get the below error when you try to update an opportunitylineitem in Salesforce:
LookupRollup: execution of AfterUpdate caused by: System.ListException: Row with null Id at index: 0 Trigger.LookupRollup: line 11, column 1
This is my code for the trigger:
Any ideas?
I have created the below code for a trigger that once an opportuntiylineitem is added, edited, deleted or undelted it SUM() the total of all product ids on opportuntilineitems as a particular status.
However I get the below error when you try to update an opportunitylineitem in Salesforce:
LookupRollup: execution of AfterUpdate caused by: System.ListException: Row with null Id at index: 0 Trigger.LookupRollup: line 11, column 1
This is my code for the trigger:
trigger LookupRollup on OpportunityLineItem (after insert,after update, after delete,after undelete) { //Declare Variables List<Product2> ProductIDs = new List<Product2>(); //Get list of all product codes on unprocessed orders ProductIDs = [ SELECT id,Other_Details__c FROM Product2 ]; //map productid to totals on orders MAP<id,AggregateResult > ProductTotal = new MAP<id,AggregateResult >( [SELECT Product2Id,SUM(NUMBER_OF_UNITS__c)vol FROM OpportunityLineItem WHERE (Opportunity.Sage_Status__c like 'Processing%' OR Opportunity.Sage_Status__c like 'Despatched%') GROUP BY Product2Id]) ; //Update to product FOR (Product2 pt : ProductIds) { STRING OnOrderTotal = string.ValueOf(ProductTotal.get(pt.id)); pt.Other_details__C = OnOrderTotal; UPSERT pt; } }
Any ideas?
All Answers
e.g. map<id,account> accountMap = new Map<id,account>[Select ID, xxx from Account];
When using aggregate function, ID not present in Select command.
You may need to change the code as below:
List<AggregateResult> AggregateResultList = [SELECT Product2Id,SUM(NUMBER_OF_UNITS__c)vol FROM OpportunityLineItem WHERE (Opportunity.Sage_Status__c like 'Processing%' OR Opportunity.Sage_Status__c like 'Despatched%') GROUP BY Product2Id]) ;
MAP<id,AggregateResult > ProductTotal = new MAP<id,AggregateResult >();
for (AggregateReulst ar: AggregateResultList)
{
ProductTotal .put (ar.product2Id,ar);
}
for (AggregateReulst ar: AggregateResultList)
{
ProductTotal .put (ID.valueof(ar.get('product2Id'),ar);
}
https://www.youtube.com/watch?v=noQWH7f8SqU