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
Becky Miller 15Becky Miller 15 

Only top-level class variables can be declared static - New Developer

A new developer and I am getting this error.  I have highlighted where the error is I cannot figure out why I am getting it.
The error is: Only top-level class variables can be declared static


 
        if(mapQuoteErrorList.get(thisQuote.Id) != null){ //|| thisQuote.Generate_Quote_as_Final__c == false){
          thisQuote.Status_Message__c = mapQuoteErrorList.get(thisQuote.Id);
        thisQuote.Generate_Quote_as_Final__c = false;
        thisQuote.Quote_Stage__c = 'DRAFT     DRAFT     DRAFT     DRAFT     DRAFT     DRAFT';
        thisQuote.Status = 'Draft'; 
        thisQuote.Date_and_Time_of_Final__c = NULL ;    
        } else {
        //if(thisQuote.Generate_Quote_as_Final__c == true) {
          thisQuote.Status_Message__c = 'Quote contains no pricing errors and requires no additional approvals.';
          thisQuote.Quote_Stage__c = 'FINAL';
          thisQuote.Status = 'Final';
          thisQuote.Generate_Quote_as_Final__c = true;
          thisQuote.Date_and_Time_of_Final__c = System.now() ;
        }    
      }
    }
   
  private static void CheckMinimumPrices(map<Id,QuoteLineItem> mapQLI,
                                            map<Id, String> mapQuoteApprovalLevel,
                                               map<Id, String> mapQuoteErrorList,
                                               map<Id, boolean> mapQuoteIsCapital){
    for(QuoteLineItem thisQL : mapQLI.values()){
        if(thisQL.UnitPrice > 0){ //|| mapQuoteIsCapital.get(thisQL.QuoteId) == null){ //if the line item is greater than zero, or there is no capital on the account
            boolean alreadySetMin = false;                                           //because if there is no capital, the zero should be treated as a value below min
            if(thisQL.PricebookEntry.UseStandardPrice
                || thisQL.PricebookEntry.Pricebook2.Name.ContainsIgnoreCase('Standard')){
                if(thisQL.PricebookEntry.RD_Minimum_Price__c != null){
                  if(thisQL.UnitPrice < thisQL.PricebookEntry.RD_Minimum_Price__c
                     && (thisQL.PricebookEntry.RD_Minimum_Price__c
                        != thisQL.PricebookEntry.Minimum_Price__c)){ //less than DOS Min and Mins are not Equal
                    if(mapQuoteApprovalLevel.get(thisQL.QuoteId) == 'Director'
                             || mapQuoteApprovalLevel.get(thisQL.QuoteId) == null){
                      if(!(mapQuoteErrorList.containsKey(thisQL.QuoteId))){        
                        mapQuoteErrorList.put(thisQL.QuoteId, 'The price quoted for ' +
                          thisQL.PricebookEntry.Product2.ProductCode
                          + ' is below the minimum price and requires Area VP approval.' + '<br/>');
                          alreadySetMin = true; {
                if(thisQL.PricebookEntry.VP_Minimum_Price__c != null){
                  if(thisQL.UnitPrice < thisQL.PricebookEntry.VP_Minimum_Price__c
                     && (thisQL.PricebookEntry.VP_Minimum_Price__c
                        != thisQL.PricebookEntry.RD_Minimum_Price__c)){ //less than RD Min and VP are not Equal
                    if(mapQuoteApprovalLevel.get(thisQL.QuoteId) == 'VP'
                             || mapQuoteApprovalLevel.get(thisQL.QuoteId) == null){
                      if(!(mapQuoteErrorList.containsKey(thisQL.QuoteId))){        
                        mapQuoteErrorList.put(thisQL.QuoteId, 'The price quoted for ' +
                          thisQL.PricebookEntry.Product2.ProductCode
                          + ' is below the minimum price and requires Marketing Director approval.' + '<br/>');
                          alreadySetMin = true;
                      } else {
                  mapQuoteErrorList.put(thisQL.QuoteId, mapQuoteErrorList.get(thisQL.QuoteId)
                  + 'The price quoted for ' +
                    thisQL.PricebookEntry.Product2.ProductCode
                    + ' is below the minimum price and requires Marketing Director approval.' + '<br/>');          
                    alreadySetMin = true;              
                      }
                    }               
                  }   
                }
                if(thisQL.PricebookEntry.Minimum_Price__c != null){
                  if(thisQL.UnitPrice < thisQL.PricebookEntry.Minimum_Price__c  //less than min
                                                                     && !alreadySetMin){
                    if(mapQuoteApprovalLevel.get(thisQL.QuoteId) == null){      
                      if(!(mapQuoteErrorList.containsKey(thisQL.QuoteId))){
                        if(!alreadySetMin){                        
                          mapQuoteErrorList.put(thisQL.QuoteId, 'The price quoted for ' +
                            thisQL.PricebookEntry.Product2.ProductCode
                            + ' is below the minimum price and requires DOS approval.' + '<br/>');
                        } 
                      } else {
                        if(!alreadySetMin){
                          mapQuoteErrorList.put(thisQL.QuoteId, mapQuoteErrorList.get(thisQL.QuoteId)
                              + 'The price quoted for ' +
                      thisQL.PricebookEntry.Product2.ProductCode
                      + ' is below the minimum price and requires DOS approval.' + '<br/>');
                        }   
                     }
             }
          } else { //not a standard price
            if(thisQL.UnitPrice < thisQL.PricebookEntry.UnitPrice
               && (mapQuoteApprovalLevel.get(thisQL.QuoteId) == null
               || mapQuoteApprovalLevel.get(thisQL.QuoteId) == 'Director')){
              if(!(mapQuoteErrorList.containsKey(thisQL.QuoteId))){     
                  mapQuoteErrorList.put(thisQL.QuoteId, 'The price quoted for ' +
                      thisQL.PricebookEntry.Product2.ProductCode
                      + ' is invalid. Discounts to GPO Prices require Area VP approval.' + '<br/>');
                      //set quote error variable to true
              } else {
              mapQuoteErrorList.put(thisQL.QuoteId, mapQuoteErrorList.get(thisQL.QuoteId)
                    + 'The price quoted for ' +
                    thisQL.PricebookEntry.Product2.ProductCode
                    + ' is invalid. Discounts to GPO Prices require Marketing Director approval.' + '<br/>');
                    //set quote error variable to true             
                    }      
                }
            }               
        }
                          }
  private static map<Id, String> QuoteApprovalLevel(set<Id> setQuoteIds){
    map<Id, String> mapQuoteApprovalLevel = new map<Id, String>();
    map<String, DateTime> mapQuoteLineItemLastTouched
      = QuoteLineItemLastTouched(setQuoteIds);
    for(ProcessInstanceStep thisPI : [SELECT StepStatus,
                                         Actor.UserRole.Name,
                                         ProcessInstance.Status,
                                         ProcessInstance.TargetObjectId,
                                         ProcessInstance.LastModifiedDate
                                   FROM ProcessInstanceStep
                                          WHERE ProcessInstance.TargetObjectId
                                          IN :setQuoteIds
                                          AND ProcessInstance.isDeleted = false
                                          AND ProcessInstance.Status = 'Approved'
                                          AND StepStatus = 'Approved'
                                          ORDER BY
                                          Actor.UserRole.Name ASC,
                                          ProcessInstance.TargetObjectId ASC,
                                                   ProcessInstance.LastModifiedDate DESC]){ 
      if(thisPI.Actor.UserRole.Name.contains('Director')){
        if(thisPI.ProcessInstance.LastModifiedDate >
            mapQuoteLineItemLastTouched.get(thisPI.ProcessInstance.TargetObjectId)){                                                    
          mapQuoteApprovalLevel.put(thisPI.ProcessInstance.TargetObjectId,'Director');
        } 
      }  
      if(thisPI.Actor.UserRole.Name.contains('VP')){
        if(thisPI.ProcessInstance.LastModifiedDate >
            mapQuoteLineItemLastTouched.get(thisPI.ProcessInstance.TargetObjectId)){                                                      
          mapQuoteApprovalLevel.put(thisPI.ProcessInstance.TargetObjectId,'VP');
        } 
      }
      if(thisPI.Actor.UserRole.Name.contains('SVP')){
        if(thisPI.ProcessInstance.LastModifiedDate >
            mapQuoteLineItemLastTouched.get(thisPI.ProcessInstance.TargetObjectId)){                                                      
          mapQuoteApprovalLevel.put(thisPI.ProcessInstance.TargetObjectId,'SVP');
        } 
      }      
                   
    return mapQuoteApprovalLevel;      
  }
  }
  private static map<String, DateTime> QuoteLineItemLastTouched(set<Id> setQuoteIds){
    map<String, DateTime> mapQuoteLineItemLastTouched
      = new map<String, DateTime>();
   
    for(AggregateResult thisAR : [SELECT QuoteId, MAX(LastModifiedDate) MaxDate FROM QuoteLineItem
                                  WHERE QuoteId IN :setQuoteIds
                                  GROUP BY QuoteId]){
      mapQuoteLineItemLastTouched.put(string.valueOf(thisAR.get('QuoteId')),
                                      DateTime.valueOf(thisAR.get('MaxDate')));
    }
    return mapQuoteLineItemLastTouched;
  }
}
 
GarryPGarryP
check if you have an inner class in your code and its variable are marked as static.