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
Sunny SohailSunny Sohail 

Illegal assignment from String to Integer

Hello,

im am trying to create a trigger that will update any accounts employee size from blank to 10 and i am getting an "Illegal assignment from String to Integer" error message. The below code should update any account that has a NULL employee size to 10. Any help would be useful.

trigger UpdateEmployeesize on Account (Before insert,after update) {
    for (account accountinloop: Trigger.new){
        if(accountinloop.NumberOfEmployees== 'NULL'){
            accountinloop.NumberOfEmployees='10';
            }
        

}
}
Best Answer chosen by Sunny Sohail
GlynAGlynA
if(accountinloop.NumberOfEmployees== null)

null is the value that means "no value".  'NULL' is a string.
 

All Answers

GlynAGlynA
if(accountinloop.NumberOfEmployees== null)

null is the value that means "no value".  'NULL' is a string.
 
This was selected as the best answer
Sunny SohailSunny Sohail
thank you for your reply. my apologies but i am fairly new to writting triggers so im not quite sure what the solution for this trigger would be. are you saying that it since "NULL" is a tring and I want the value of the field to update to a number this will not be possible?
Sunny SohailSunny Sohail
nevermind I figured it out.

trigger UpdateEmployeesize on Account (Before insert,after update) {
    for (account accountinloop: Trigger.new){
        if (accountinloop.NumberOfEmployees== null )
            accountinloop.NumberOfEmployees=10;
            }
        }

thank you :)