function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TilluTillu 

How to write summerized amount in a Trigger ?

I have contact , policy,Transaction objects are there. I want to display  summerized amount of Transaction   on  contact field. Can anyone improve below code.

trigger ConPoliTrigger on Contact (before insert,after update) {

Set<id>  Cset = new set<id>();
List<Contact> Clist = new List<Contact>();

for(Contact c:Trigger.new){
Cset.add(c.id);
}


List<Policy__c> pi = [select id,name,Contact__c from Policy__c where Contact__c in:Cset];
List<Transaction__c> Tr = [select id,name,Policy__c from Transaction__c where policy__c in:Pi AND Posted_Date__c > NEXT_N_DAYS:365 ];

for(Contact ca:Trigger.new){
for(Policy__c po:pi){
for(Transaction__c Ta:Tr){

if(Transaction__c Tran : Trigger.new){
kkkif(po.Type__c == 'VA'){
ca.X12_Months__c = po.Amount__c;

}
}
}
}
CList.add(ca);
}
//update Clist;
}
Shashikant SharmaShashikant Sharma
It looks you are working on wrong object and wrong event. Your trigger should be on Transaction insert, Update and Delete as it is rolled up to contact. 


This trigger has many issues first is that you have Cset.add(c.id); in before insert . Record Id only come in After Insert.