You need to sign in to do that
Don't have an account?
Girbson Bijou
Trigger to Roll-up on lookup relationship
I have a lookup relationship between Contract(Parent) and Expenses__c
want to summarize the value of the field called Amout in Expenses__c to a custom field in Contract called Tot_instalment__c. Please help me to find where the errors are in the code. Attached is the list of the problem.
want to summarize the value of the field called Amout in Expenses__c to a custom field in Contract called Tot_instalment__c. Please help me to find where the errors are in the code. Attached is the list of the problem.
trigger UpdateTotInstalment on Expenses__c (after insert, after delete, after undelete, after update) { set<id> ids=new set<id>(); for(Expenses__c exp: trigger.new) ids.add(exp.ContractNumber__c); List<contract> contractToUpdate=new List<Contract>(); Map<ID, contract> cont = new Map<ID, contract>([select id ,Tot_Instalment__c from Contract where id:=ids]); AggregateResult[] groupedResults = [SELECT ContractNumber__c,SUM(Amount__c)amt FROM Expenses__c where ContractNumber__c in:ids group by ContractNumber__c]; for(AggregateResult Results: groupedResults){ Id ContractNumber__c =(id) Results.get('ContractNumber__c'); Contract c = cont.get(ContractNumber__c); c.Tot_Instalment__c=(integer)Results.get('amt'); contractToUpdate.add(c); } update contractToUpdate; }
All Answers
Try with the alias set for the field you are querying.
Try the below code:
Hope this will helpful.
Thanks.