+ Start a Discussion

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


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 
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){
        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){
             if(SSJ.Start_Date_and_Time__c!=NULL && SSJ.End_Date_and_Time__c!=NULL ){
                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" */
Art SmorodinArt Smorodin
Have you tried the "valueOf" function? 

What happens if you replace 
    SSJ.FA_Job_Time__c=Days + ' Days  ' + Hours + ' Hours  ' + Minutes + ' Minutes';
    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 .