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
jameskCAjameskCA 

Number field with 0 decimal places not an integer?

I have a trigger with some code that references a number field with 18, 0.  My method returns an integer and the quantity variable is an integer, however when I try and use the field value I get the following error:

Method does not exist or incorrect signature: dcSystemSize(String, Decimal)

here is all the relevant code:
Map<String, Integer> panelType = new Map<String,Integer>{'Hyundai 255'=>255,'Hyundai 280'=>280,'Trina 290'=>290,'Hyundai 325'=>325,'SW Mono 280'=>280,'Hyundai 290'=>290};

 public Integer dcSystemSize(String panel, Integer qty){
                    
        Integer panelWattage = panelType.get(panel);
        return ((panelWattage * qty)/1000);
    } 

 for(Proposal__c p:Trigger.new){
 p.System_Size_kW__c = dcSystemSize(p.Panel_Type__c,p.Panel_Qty__c);
}

Is there any way to assign a field to an Integer variable?  Or, are they always decimal?  
Best Answer chosen by jameskCA
Sumit Kumar Singh 9Sumit Kumar Singh 9
You can cast it to integer.
p.System_Size_kW__c = dcSystemSize(p.Panel_Type__c,(Integer) p.Panel_Qty__c);
OR
p.System_Size_kW__c = dcSystemSize(p.Panel_Type__c,Integer.valueOf(p.Panel_Qty__c));

Thanks,
Sumit

All Answers

Sumit Kumar Singh 9Sumit Kumar Singh 9
You can cast it to integer.
p.System_Size_kW__c = dcSystemSize(p.Panel_Type__c,(Integer) p.Panel_Qty__c);
OR
p.System_Size_kW__c = dcSystemSize(p.Panel_Type__c,Integer.valueOf(p.Panel_Qty__c));

Thanks,
Sumit
This was selected as the best answer
jameskCAjameskCA
Thanks, that worked.  Is there any benefit to using integers when I'm getting and setting number fields in salesforce?  Should I always just use decimal?