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
cathy369cathy369 

Invalid type error in apex class

this should be so simple, but as i'm not any kind of OOP developer, and do not know java, c++ and/or apex, i have no idea what the issue might be... i get Compile Error: Invalid type; baseMOCharge at line 27....

 

any help is greatly appreciated.

public class MOCharge{

   public static decimal[] getMOCharge(boolean stdWin, 
                                       boolean spcWin, 
                                       boolean dblWin,
                                       boolean noWin,
                                       boolean MOWinDie,
                                       decimal wrkPerMQty,
                                       decimal wrkQty,
                                       decimal closureCharge,
                                       List<Mfg_Run_Charges__c> mrcRC1){

      decimal[] charges = new decimal[]{0,0};
      decimal baseMOCharge = 0.0;
      
      for(Mfg_Run_Charges__c MO : mrcRC1) {
         if (MO.Process_Code__c=='MO' && MO.Min_Qty__c <=wrkQty && MO.Max_Qty__c >=wrkQty){
            baseMOCharge = (MO.Set_Up_Cost__c / WrkPerMQty) + (MO.Run_Rate__c / (MO.Qty_per_Hour__c / 1000) );
            if ((noWin) || (stdWin && MOWinDie)){
               charges[0] = baseMOCharge + closureCharge;
            }else{
               if (dblWin){
                  if (!MOWinDie){
/// BELOW LINE IS WHERE THE INVALID TYPE ERROR OCCURS....
                     charges[0] = (baseMOCharge) + MO.Punch_Patch_Setup__c + (MO.Punch_Patch_M__c * WrkPerMQty); 
                     charges[1] = MO.Miscellaneous_Charge__c;
                  }else{
                     charges[0] = (((baseMOCharge) + MO.Punch_Patch_Setup__c + (MO.Punch_Patch_M__c * WrkPerMQty))+ ClosureCharge) * MO.Special_Window__c; 
                  }
               }else{
                  if (SpcWin){
                     if (!MOWinDie){
                        charges[0] = (baseMOCharge) + MO.Punch_Patch_Setup__c + (MO.Punch_Patch_M__c * WrkPerMQty) + ClosureCharge; 
                        system.debug('SpcWin - No MO Die: ' + charges[0] + ', ' + MO.Per_M_Charge__c + ', ' + MO.Punch_Patch_Setup__c + ', ' + MO.Punch_Patch_M__c);
                     }else{
                        system.debug('before charges[0]: ' + charges[0]);
                        charges[0] = ((baseMOCharge) + ClosureCharge ) * MO.Special_Window__c;
                        system.debug('wtf??? charges[0],ClsrChg,MO.SpclWin,: ' + charges[0] + ', ' + closureCharge + ', ' + MO.Special_Window__c);
                     }
                  }else{
                        charges[0] = (baseMOCharge) + MO.Punch_Patch_Setup__c + (MO.Punch_Patch_M__c * WrkPerMQty); 
                  }    
               }
            }
         break;
         }
      }
    return charges;
    }
 }

 

Best Answer chosen by Admin (Salesforce Developers) 
Tim BarsottiTim Barsotti

Change the line that is failing to this:

 charges[0] = (baseMOCharge + MO.Punch_Patch_Setup__c + (MO.Punch_Patch_M__c * WrkPerMQty)); 

 You will need to make the changes throughout. The parenthesis or lack thereof will cause that issue.

All Answers

Tim BarsottiTim Barsotti

Change the line that is failing to this:

 charges[0] = (baseMOCharge + MO.Punch_Patch_Setup__c + (MO.Punch_Patch_M__c * WrkPerMQty)); 

 You will need to make the changes throughout. The parenthesis or lack thereof will cause that issue.

This was selected as the best answer
cathy369cathy369
thanks so much. I was so frustrated and knew it was something obvious.
thanks again.



Cathy Halper

Desert Paper & Envelope Company, Inc.

505.884.0640



PRINT! The renewable way a responsible world communicates.