Find your content:

Search form

You are here

arithmetic expression must use numeric argument

 
Share

This error is driving me crasy

arithmetic expression must use numeric argument

obj.Without_credit_time_off_amount__c =( (User.Salary__c)/30)*obj.Days__c;

Without_credit_time_off_amount__c currency type
Days__c formula field, number type
Salary__c is a currency type

I've tried to cast the salary__c value but in vain


Attribution to: LoveLace

Possible Suggestion/Solution #1

I figured out something, is that I cant manipulate a custom field on user without inisialised it !!!! is there any other way to manipulate it without inisialised it?


Attribution to: LoveLace

Possible Suggestion/Solution #2

I think zdropic has identified the problem. With no other variables involved:

User.Salary__c

is an SObjectField token and can't be used in an arithmetic expression. (Its purpose is to provide a compile-time checked token that represents a field of an SObject; it can be used with SObject.get and SObject.put and in describe calls.) If you have a variable called User (or user given the Apex compiler's case insensitivity) in scope, that would normally have precedence, but it is clearer to not user variable names that are identical to object type names.

There is no global User object, there is only a global UserInfo object. So I would expect code looking like this to work here:

User u = [select Salary__c from User where Id = :UserInfo.getUserId()];
obj.Without_credit_time_off_amount__c = (u.Salary__c / 30) * obj.Days__c;

Attribution to: Keith C
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/31139

My Block Status

My Block Content