Created
August 21, 2020 04:16
-
-
Save jamesasu/04b695aaca8e006b991eeaf37eeb8a39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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