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
mng0827mng0827 

Comparison arguments must be compatible types: String, Integer

Hi,

I'm trying to create a trigger to update 2 picklist fields based on the value of a number field. However, I get the following error on line 5:

"Comparison arguments must be compatible types: String, Integer"

Here's my code:
________________________________________________________

trigger UpdateHHIncome on Account (before insert, before update) {

    Account acct = trigger.new[0];
    {
        if(acct.Household_Income__c == 1){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';     
           acct.Household_Income__c = 'Up to $8,925';}
        else if(acct.Household_Income__c == 2){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';
           acct.Household_Income__c = '$8,926 - $36,250';}
        else{acct.Tax_Filing_Status_Peakfolio__c = 'Single';
             acct.Household_Income__c = '$36,251 - $87,850';}
    }
}
AshesAshes
To Compare with Any String you need to Convert integer in to String using String.valueOf() funtion.
Also you can compare expression like acct.Household_Income__c = 'Up to $8,925' instead you can write acct.Household_Income__c>=8925. Dont use special characters while comparing integers with String

Ash
mng0827mng0827
Thanks Ashes. Can you provide a sample code using the String.valueOf() function?
Vinit_KumarVinit_Kumar
Try below code :-

trigger UpdateHHIncome on Account (before insert, before update) {

    Account acct = trigger.new[0];
    {
        if(acct.Household_Income__c == '1'){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';     
           acct.Household_Income__c = 'Up to $8,925';}
        else if(acct.Household_Income__c == '2'){
           acct.Tax_Filing_Status_Peakfolio__c = 'Single';
           acct.Household_Income__c = '$8,926 - $36,250';}
        else{acct.Tax_Filing_Status_Peakfolio__c = 'Single';
             acct.Household_Income__c = '$36,251 - $87,850';}
    }
}

If this helps,please mark it as best answer to help others :)