How to compare map values in condition if map keyset contains provided key and its value is NO get inside If condition which is in loop

Availability__c is a picklist containing Yes and No values

want to know how to put this condition if map keyset contains provided key and its value is NO get inside If condition which is in loop I have used if( newmap.containskey(pbdObj.product__c) =='No' )

@AuraEnabled   
    public static List<PriceDetail> getPriceBookDetails(pricebook__c pbdObj){
        
        Map<Id,String> newmap = new Map<Id,String>();
        
        for( Combination__c temp:[SELECT Id, product__c, Sales_District__c, Availability__c FROM Combination__c where Sales_District__c =:regCode] )
        {
            
            newmap.put(temp.product__c, temp.Availability__c);
            
        }
        pd.productId = pbdObj.product__c;
        
        if( newmap.containskey(pbdObj.product__c) =='No'  ){
            
            system.debug('**Inside Map Availability No **');
            
            pd.avail = false;
        }
    }

Answers 1

  • You have to add 2 conditions in IF ie

    1. Check if the key exists in the map AND

    2. If the value corresponding to the key id 'NO'

      if(newmap.containskey(pbdObj.product__c) && newmap.get(pbdObj.product__c) == 'No')


Related Questions