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
sundhar.mks1.3962649227519546E12sundhar.mks1.3962649227519546E12 

Urgent: Error: Compile Error: Illegal assignment from String to Decimal at line

Hi

I have used the following code to update the field jobTime field, When i save the code i got "Error: Compile Error: Illegal assignment from String to Decimal at line". The Reason  Field type is "Number". I can not change the field type because "JobTime" field refered in somany place.
Can i Modify the following code? Is this possible? Kindly give any idea 
=================================
Code
=================================
public void JobTimeUpdate(List<Engineer_Checklist__c> newSSJList){
        List<ID> SSJIds= New List<ID>();
        List<Engineer_Checklist__c> SSJList= New List<Engineer_Checklist__c>();
        Integer Days;
        Integer Hours;
        Integer Minutes ;
        
        for(Engineer_Checklist__c SSJ:newSSJList){
            SSJIds.add(SSJ.id);
        }
        SSJList= [Select id,Start_Date_and_Time__c, End_Date_and_Time__c, FA_Job_Time__c from Engineer_Checklist__c where Id=:SSJIds ];
        
        for(Engineer_Checklist__c SSJ:newSSJList){
            Days=Hours=Minutes=0;
           
             if(SSJ.Start_Date_and_Time__c!=NULL && SSJ.End_Date_and_Time__c!=NULL ){
                Days=Date.ValueOf(SSJ.Start_Date_and_Time__c).daysBetween(date.valueOf(SSJ.End_Date_and_Time__c));    
                Hours = math.mod(integer.valueOf(((SSJ.End_Date_and_Time__c).getTime() - (SSJ.Start_Date_and_Time__c).getTime())/(1000*60*60)),24);                          
                Minutes = math.mod(Integer.valueOf(((SSJ.End_Date_and_Time__c).getTime() - (SSJ.Start_Date_and_Time__c).getTime())/(1000*60)),60);
                system.debug(Days +'***Days*** ' + '***Hours*** ' + Hours + '***Minutes*** ' + Minutes);
                SSJ.FA_Job_Time__c=Days + ' Days  ' + Hours + ' Hours  ' + Minutes + ' Minutes';  /*Error: Compile Error: Illegal assignment from String to Decimal at line" */
            }
            System.debug('SSJ.FA_Job_Time__c'+SSJ.FA_Job_Time__c);
        }
    }
Art SmorodinArt Smorodin
Hi,
Have you tried the "valueOf" function? 
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_integer.htm

What happens if you replace 
    SSJ.FA_Job_Time__c=Days + ' Days  ' + Hours + ' Hours  ' + Minutes + ' Minutes';
    with 
    SSJ.FA_Job_Time__c=valueOf(Days + ' Days  ' + Hours + ' Hours  ' + Minutes + ' Minutes');
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@sundhar.mks1.3962649227519546E12 :

With out changing the field type, ideally you can either  store no of Days or hours or minutes count in that field .  If it is being reffered in other parts of code, i would suggest do an analysis, change the code logic to handle this field as a text based value .