You need to sign in to do that
Don't have an account?

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);
}
}
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
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 ?
Ritesh,
Yes, all are numerical fields. What would generate the error 'numeric arguments'? Wish the errors where better define.
Norm
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);
}
}
Can I ask why __r instead of the __c field designation?
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);
}
}
Testing now.