How to compare values in Custom Metadata with given object in Apex – User friendly Tech help

Problem- Admin wants some value as configurable and set in custom metadata, now as a developer, we want to perform an action based on the matching of this mdt with values in say platform field on the account object

n

  public Boolean validatePlatform() {n        System.debug('Inside validatePlatform');n        List lstOfPlatforms = new List(); n        Boolean isValidPlatform = false;n        String thePlatform = 'Amazon';nn        //fetching the allowed sw platform from custom settings n        List givenPlatforms = new List([n            SELECT SDFC_software_platform_value__c n            from Allowed_Platform__mdt n        ]);nn        for(Allowed_Platform__mdt mdt :givenPlatforms ){n            lstOfPlatforms.add(mdt.platform__c);n        }n        System.debug('lstOfPlatforms = '+lstOfPlatforms );nn        //incase list contains the custom settings then do the comparison with platform n        if(!lstOfPlatforms.isEmpty() && lstOfPlatforms.contains(thePlatform)){n            System.debug('thePlatform = '+thePlatform );n            return true;n        }nn        return isValidPlatform;n    }
Was this article helpful?
YesNo

Similar Posts