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
BeekmanBeekman 

Arithmetic expression must use numeric arguments

Hello,

 

Dont understand why I am getting this error on the code below.  Isnt a (-) and a (+) an arithmetic expression LOL

 

any help as I am new to Appex.

 

trigger Peachtree_items_process on Peachtree_items__c (after update, after insert) {
    if (Peachtree_items__c.Stock_Minimum__c != null && Peachtree_items__c.Qty_On_Hand__c != null &&
            Peachtree_items__c.Qty_On_PO__c != null) {
            Peachtree_items__c.Stock_Reorder_Qty__c =
                Peachtree_items__c.Stock_Minimum__c -
                    (Peachtree_items__c.Qty_On_Hand__c + Peachtree_items__c.Qty_On_PO__c);
    }
}

Best Answer chosen by Beekman
Ritesh AswaneyRitesh Aswaney

You nearly made me forget the syntax there !! I've corrected the trigger above, try that to see if it works.

 

You need to have a for loop to iterate over all the records that have invoked the trigger.


Also a before trigger makes more sense, since you're manipulating values on the triggering records.

 

trigger Peachtree_items_process on Peachtree_items__c (before update, before insert) {

 

for( PeachTree_Items__c peachTreeItem : trigger.new) //iterate over all items
    if (peachTreeItem.Stock_Minimum__c != null  && peachTreeItem.Qty_On_Hand__c != null &&
            peachTreeItem.Qty_On_PO__c != null) {
            peachTreeItem.Stock_Reorder_Qty__c =
                peachTreeItem.Stock_Minimum__c -
                    (peachTreeItem.Qty_On_Hand__c + peachTreeItem.Qty_On_PO__c);
    }
}

All Answers

Ritesh AswaneyRitesh Aswaney

Its talking about the fields, not the operators :)

Are all of the fields in the expression numerical ? i.e. Stock_Reorder_Qty__c, Stock_Minimum__c, Qty_On_Hand__c & Qty_On_PO__c 

 

Or are they Text ?

BeekmanBeekman

Ritesh,

 

Yes, all are numerical fields.  What would generate the error 'numeric arguments'?  Wish the errors where better define.

 

Norm

Ritesh AswaneyRitesh Aswaney

Just noticed, all of your relationship references should be __r rather than __c. Also you need to iterate over all items in trigger. new. Also a before trigger makes more sense since youre manipulating values on the records that fired the trigger.

 

So

 

trigger Peachtree_items_process on Peachtree_items__c (before update, before insert) {

 

for( PeachTree_Items__c peachTreeItem : trigger.new) //iterate over all items
    if (peachTreeItem.Stock_Minimum__c != null  && peachTreeItem.Qty_On_Hand__c != null &&
            peachTreeItem.Qty_On_PO__c != null) {
            peachTreeItem.Stock_Reorder_Qty__c =
                peachTreeItem.Stock_Minimum__c -
                    (peachTreeItem.Qty_On_Hand__c + peachTreeItem.Qty_On_PO__c);
    }
}

BeekmanBeekman

Can I ask why __r instead of the __c field designation? 

Ritesh AswaneyRitesh Aswaney

You nearly made me forget the syntax there !! I've corrected the trigger above, try that to see if it works.

 

You need to have a for loop to iterate over all the records that have invoked the trigger.


Also a before trigger makes more sense, since you're manipulating values on the triggering records.

 

trigger Peachtree_items_process on Peachtree_items__c (before update, before insert) {

 

for( PeachTree_Items__c peachTreeItem : trigger.new) //iterate over all items
    if (peachTreeItem.Stock_Minimum__c != null  && peachTreeItem.Qty_On_Hand__c != null &&
            peachTreeItem.Qty_On_PO__c != null) {
            peachTreeItem.Stock_Reorder_Qty__c =
                peachTreeItem.Stock_Minimum__c -
                    (peachTreeItem.Qty_On_Hand__c + peachTreeItem.Qty_On_PO__c);
    }
}

This was selected as the best answer
BeekmanBeekman

Testing now.