+ Start a Discussion
sonam gupthasonam guptha 

after delete is not working on rollup summary of particular recordtype

Hello,

i have a custom object member,here i need to sum-up each record type value total_column__c and print on account,everything is working as expected,but after delete is not working.
for example:—
i have account.ITWING__c = 1000
and member. total_column__c = 500
if i delete member record,account.ITWING__c = 500 should be 500.
but this is not working as expected,please help me out to resolve it.
 
trigger updatetotalAccount on Member__c (After Insert,After update,After Delete)
{

		List<Account> recTypeITdeleteList = new List<Account>();
        List<Account> recTypeITUpdateList = new List<Account>();
        List<Account> recTypeFinanceList = new List<Account>();
	
	Id recTypeIT = [SELECT Id FROM RecordType WHERE name='ITWING' AND SObjectType='member__c' LIMIT 1].Id;
    Id recTypeFinance = [SELECT Id FROM RecordType WHERE name='Finance' AND SObjectType=‘member__c' LIMIT 1].Id;
    
		string ids;
		if(Trigger.isInsert || Trigger.isUpdate)
		{
		for(Member__c objMember : Trigger.new){
		if(objMember.lookupAccount__c != null)
		ids= objMember.id;
		    }
		}
		if(Trigger.isDelete){
		for(Member__c objMember : Trigger.old){
		if(objMember.lookupAccount__c != null)
		ids= objMember.id;
		If(mem.RecordTypeId=recTypeIT)
		{
		for(opportunity opp : [Select Id,AccountId from Opportunity where Id=:mem.lookupOpportunity__c ]){
		for(Account acc:[Select Id,ITWING__c,Finance__c from Account where Id=:opp.AccountId]){
		for(Account aaa:acc){
		if(acc.ITWING__c == null){
		aaa.ITWING__c=null;
		}else 
		aaa.ITWING__c -= mem.total_column__c;
		}
		}
		recTypeITdeleteList.add(aaa);

		    }}}}
		    
		for(Member__c mem :[select Id,lookupAccount__c,total_column__c,RecordTypeId from Member__c where ID=:ids]){
		If(mem.RecordTypeId=recTypeIT)
		{
		for(opportunity opp : [Select Id,AccountId from Opportunity where Id=:mem.lookupOpportunity__c ]){
		for(Account acc:[Select Id,ITWING__c,Finance__c from Account where Id=:opp.AccountId]){
		for(Account aaa:acc){
		if(acc.ITWING__c == null){
		aaa.ITWING__c=mem.total_column__c;
		}else 
		aaa.ITWING__c+=mem.total_column__c;
		}
		}
		recTypeITUpdateList.add(aaa);
		}}

		elseIf(mem.RecordTypeId=recTypeFinance)
		{
		for(opportunity opp : [Select Id,AccountId from Opportunity where Id=:mem.lookupOpportunity__c ]){
		for(Account acc:[Select Id,ITWING__c,Finance__c from Account where Id=:opp.AccountId]){
		for(Account bbb:acc1){
		bbb.ITWING__c=mem.total_column__c;
		if(acc.ITWING__c == null){
		bbb.ITWING__c=mem.total_column__c;
		}else 
		bbb.ITWING__c+=mem.total_column__c;
		}
		}
		recTypeITUpdateList.add(bbb);
		}}

		update recTypeITUpdateList;
		update recTypeFinanceList;
		update recTypeITdeleteList;

}}}