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
Paulo PerezPaulo Perez 

Arithmetic expressions must use numeric arguments

Dear 

I need assistane. I dont know more what i can do, show me "Arithmetic expressions must use numeric arguments at line 13 column 29"


public class FrequenciaCompra{
    public static void Frequencia(Account[] Conta) {
        for (Account b :Conta){
            AggregateResult[]  opp =
                [SELECT accountid,count(CloseDate) n
                FROM Opportunity
                WHERE 
                CloseDate>=:b.Primeira_Oportunidade__c and
                CloseDate<=:b.Ultima_Oportunidade__c and
                accountid=:b.id
                group by accountid] ;
            date startDate=b.Ultima_Oportunidade__c;
            b.Frequencia__C=startDate.daysBetween(b.Primeira_Oportunidade__c)/opp[0].get('n');
            b.update;
        }
    }
    
}
sandeep sankhlasandeep sankhla
Hi Paul,

Try to replace your line with this below line and check..

  b.Frequencia__C=(startDate.daysBetween(b.Primeira_Oportunidade__c))/opp[0].get('n');
Paulo PerezPaulo Perez
Hello Sandeep

:\ still does not work
andy81andy81
Check with the data types for fields whether all the fields mentioned in class are of numeric data type or there are any text data types. Expression checks only for numeric fields if there are any non numeric or text fields then it throws an exception.
Paulo PerezPaulo Perez
Every fields used are numeric type.
andy81andy81
Try this code.
b.Frequencia__C=Integer.valueof(startDate.daysBetween(b.Primeira_Oportunidade__c))/Integer.value(opp[0].get('n'));
Paulo PerezPaulo Perez
Well, changed the Error, rsrsrs,  " Variable does not exist: Integer na linha 13 coluna 96":

public class FrequenciaCompra{
    public static void Frequencia(Account[] Conta) {
        for (Account b :Conta){
            AggregateResult[]  opp =
                [SELECT accountid,count(CloseDate) n
                FROM Opportunity
                WHERE 
                CloseDate>=:b.Primeira_Oportunidade__c and
                CloseDate<=:b.Ultima_Oportunidade__c and
                accountid=:b.id
                group by accountid] ;
            date startDate=b.Ultima_Oportunidade__c;
            b.Frequencia__C=Integer.valueof(startDate.daysBetween(b.Primeira_Oportunidade__c))/Integer.value(opp[0].get('n'));
            update b;
        }
    }
    
}
Paulo PerezPaulo Perez
Thank everybody!!!

I found my mystake, now it works!! :)

public class FrequenciaCompra{
    public static void Frequencia(Account[] Conta) {
        List<Account> accsToUpdate = new List<Account>(); 
        for (Account b :Conta){
            AggregateResult[]  opp =
                [SELECT accountid,count(CloseDate) n
                FROM Opportunity
                WHERE 
                CloseDate>=:b.Primeira_Oportunidade__c and
                CloseDate<=:b.Ultima_Oportunidade__c and
                accountid=:b.id
                group by accountid] ;
            date startDate=b.Ultima_Oportunidade__c;
            b.Frequencia__C=startDate.daysBetween(b.Primeira_Oportunidade__c)/(integer)opp[0].get('n');         
                
        accsToUpdate.add(b);}
        update accsToUpdate;        }
    }