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
anil Anil5anil Anil5 

Error: Compile Error: Arithmetic expressions must use numeric arguments at line 15 column 13




trigger RollUpSummaryUpdate on Company__c(after insert,after update){
           
               double totalSum = 0;

    Set<Id> Parentids = New Set<Id>();
    
    for(integer i=0;i<Trigger.new.Size();i++){
       Parentids.add(Trigger.new[i].Clients__c);
    }
    
    List<Client__c> AP = [SELECT ID,(SELECT ID FROM Company__r) FROM Client__c WHERE ID=:Parentids];
    
    for(Client__c apUpdates:AP){
    
            totalSum += Company__c.Amount__c; 
        apUpdates.Sum__c =totalSum;
    }
    Update AP;
}
Himanshu ParasharHimanshu Parashar
Hi Anil,

It is because Company__c.Amount__c doesn't exist anywhere. if you are using trigger you will write it as
 
totalSum += Trigger.new[0].Amount__c;
Though it is not a good practice but I am assuming that you are always updating a single record.

Thanks,
Himanshu
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help you
trigger RollUpSummaryUpdate on Company__c(after insert,after update)
{
    Integer totalSum = 0;
    Set<Id> Parentids = New Set<Id>();
    
    for(integer i=0;i<Trigger.new.Size();i++)
	{
       Parentids.add(Trigger.new[i].Clients__c);
    }
    
    List<Client__c> AP = [SELECT ID,Sum__c,(SELECT ID,Amount__c FROM Company__r) FROM Client__c WHERE ID=:Parentids];
	List<Client> lstClientToUpdate = new List<Client>();
    
    for(Client__c apUpdates: AP )
	{	
		totalSum = 0;
		List<Company__c> listCompany = apUpdates.Company__r;
		for( Company__c comp : listCompany)
		{
			if(comp.Amount__c != null)
			{
				totalSum += comp.Amount__c; 
			}
		}
		apUpdates.Sum__c = totalSum;
		lstClientToUpdate.add(apUpdates);
    }
	if(lstClientToUpdate.size() > 0)
	{
		Update lstClientToUpdate;
	}	
}
Please lst us k now if this will help you

Thanks,
Amit Chaudhary