Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jamesasu/04b695aaca8e006b991eeaf37eeb8a39 to your computer and use it in GitHub Desktop.
Save jamesasu/04b695aaca8e006b991eeaf37eeb8a39 to your computer and use it in GitHub Desktop.
public with sharing class MyCustomMetadataHandler {
@AuraEnabled
public static Boolean saveDefaultDecimal(Decimal value) {
Id orgId = UserInfo.getOrganizationId();
List<My_Custom_Metadata_Default__c> defs = [SELECT Id, SetupOwnerId, Percentage_Value__c FROM My_Custom_Metadata_Default__c WHERE SetupOwnerId = :orgId];
Database.SaveResult defSave;
if (defs.size() == 0) {
My_Custom_Metadata_Default__c nd = new My_Custom_Metadata_Default__c(
SetupOwnerId = orgId,
Percentage_Value__c = value
);
defSave = Database.insert(nd, false);
} else {
My_Custom_Metadata_Default__c def = defs[0];
def.Percentage_Value__c = value;
defSave = Database.update(def, false);
}
return defSave.isSuccess();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment