Mtadata Types - Record changes by apex
List<SNO_GVC_Reservation_Soft_Lock_Release__mdt> metaList = [Select MasterLabel,DeveloperName,SNO_GVC_Soft_Lock_Release_Timer__c From SNO_GVC_Reservation_Soft_Lock_Release__mdt];
//instance of the record
Metadata.CustomMetadata mdata = new Metadata.CustomMetadata();
mdata.fullName = 'SNO_GVC_Reservation_Soft_Lock_Release__mdt.'+country ;
// here country - mewns record value for field (api name) on each record. for upsert --- if we would like to create new record we can give new uniqu name
mdata.label = country;
//instance of the value
Metadata.CustomMetadataValue instance = new Metadata.CustomMetadataValue();
instance.field = 'SNO_GVC_Soft_Lock_Release_Timer__c'; // feild api name to whome we would like to assign value
instance.value = timerint; //assign value to the above fields
//adding the value to the record
mdata.values.add(instance);//
//instance of the container
Metadata.DeployContainer container = new Metadata.DeployContainer();
container.addMetadata(mdata);
//enqueue deployment to the salesforce org'
if(!Test.isRunningTest())
Metadata.Operations.enqueueDeployment(container, null);
}
https://www.youtube.com/watch?v=ahTCojQ-Lc8
Notes :
If we updating : developer name is there then it will update
for creation : datatype validation, required fields need to create other than developername .
Comments
Post a Comment