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


https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Metadata_CustomMetadata.htm

https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Metadata_DeployContainer.htm?q=Metadata.DeployContainer


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

Popular posts from this blog

How to get sessionid and salesforce org base url in salesforce

salesforce - sf - sfdx - cli - commands

Multi currency in Salesforce - Revenue Cloud Advance - Revenue Lifecycle Management