31 Comments

  1. Hi Amit,

    I have a question from step 4 onward,
    I mean do we need to execute the code in an isolated way in dev console.
    I am a bit confused.

    Regards,
    Siddhartha

    • Hi Siddhartha,

      The Code that I am using in Anonymous Window is just for testing Purpose. You can call the method from Apex Class As well. But the Parameters must be of the same DataType because this code is for generic metadata that means you can use this code for creating any metadata records.

  2. Hi Amit,
    Thank you for the clear explanation!
    I ran this code, but don’t see any result.
    Maybe it because I have a free developer account?

    Here is my log:
    45.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;NBA,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
    08:11:30.34 (34107709)|USER_INFO|[EXTERNAL]|0054J000000vzkk||(GMT+01:00) Greenwich Mean Time (Europe/Dublin)|GMT+01:00
    08:11:30.34 (34278345)|EXECUTION_STARTED
    08:11:30.34 (34293422)|CODE_UNIT_STARTED|[EXTERNAL]|DeployWorker.enqueueApexCallback
    08:11:30.34 (42528076)|HEAP_ALLOCATE|[72]|Bytes:3
    08:11:30.34 (42713894)|HEAP_ALLOCATE|[77]|Bytes:152
    08:11:30.34 (42744856)|HEAP_ALLOCATE|[342]|Bytes:408
    08:11:30.34 (42789823)|HEAP_ALLOCATE|[355]|Bytes:408
    08:11:30.34 (42810224)|HEAP_ALLOCATE|[467]|Bytes:48
    08:11:30.34 (42920776)|HEAP_ALLOCATE|[139]|Bytes:6
    08:11:30.34 (42951473)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:552
    08:11:30.34 (43021331)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:68
    08:11:30.34 (43113163)|SYSTEM_METHOD_ENTRY|[2]|DeployResult.DeployResult()
    08:11:30.34 (43154492)|STATEMENT_EXECUTE|[2]
    08:11:30.34 (43224544)|SYSTEM_METHOD_EXIT|[2]|DeployResult
    08:11:30.34 (55291093)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
    08:11:30.34 (55339884)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (55820141)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.id|”0Af4J00000FqesASAR”|0x78e908ab
    08:11:30.34 (55925653)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:15
    08:11:30.34 (55942250)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (55994577)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.canceledBy|”000000000000000″|0x78e908ab
    08:11:30.34 (56669706)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (56719433)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.canceledByName|null|0x78e908ab
    08:11:30.34 (56853642)|HEAP_ALLOCATE|[50]|Bytes:5
    08:11:30.34 (56894877)|HEAP_ALLOCATE|[56]|Bytes:5
    08:11:30.34 (56911997)|HEAP_ALLOCATE|[64]|Bytes:7
    08:11:30.34 (56936537)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (56946082)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (56979132)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.checkOnly|false|0x78e908ab
    08:11:30.34 (57204445)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (57217384)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (57290246)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.completedDate|”2019-05-26T07:11:31.000Z”|0x78e908ab
    08:11:30.34 (57324429)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:15
    08:11:30.34 (57346383)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (57368225)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.createdBy|”0054J000000vzkk”|0x78e908ab
    08:11:30.34 (67049917)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:19
    08:11:30.34 (67083647)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (67172841)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.createdByName|””|0x78e908ab
    08:11:30.34 (67246867)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (67257491)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (67306616)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.createdDate|”2019-05-26T07:11:30.000Z”|0x78e908ab
    08:11:30.34 (67370125)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:136
    08:11:30.34 (67430216)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (67539123)|SYSTEM_METHOD_ENTRY|[3]|DeployDetails.DeployDetails()
    08:11:30.34 (67551483)|STATEMENT_EXECUTE|[3]
    08:11:30.34 (67590403)|SYSTEM_METHOD_EXIT|[3]|DeployDetails
    08:11:30.34 (67816706)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
    08:11:30.34 (67835706)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
    08:11:30.34 (67844783)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
    08:11:30.34 (68091282)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:332
    08:11:30.34 (68151821)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:38
    08:11:30.34 (68191369)|SYSTEM_METHOD_ENTRY|[2]|DeployMessage.DeployMessage()
    08:11:30.34 (68200836)|STATEMENT_EXECUTE|[2]
    08:11:30.34 (68218117)|SYSTEM_METHOD_EXIT|[2]|DeployMessage
    08:11:30.34 (68672711)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (68697115)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (68732582)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.changed|false|0x68e2f535
    08:11:30.34 (68761561)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (68781518)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.columnNumber|null|0x68e2f535
    08:11:30.34 (68804928)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:14
    08:11:30.34 (68813089)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (68833354)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.componentType|”CustomMetadata”|0x68e2f535
    08:11:30.34 (68858094)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (68864847)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (68882702)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.created|false|0x68e2f535
    08:11:30.34 (68905681)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (68913919)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (68950400)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.createdDate|”2019-05-26T07:11:30.925Z”|0x68e2f535
    08:11:30.34 (68975876)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (68984373)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69001618)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.deleted|false|0x68e2f535
    08:11:30.34 (69062842)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:43
    08:11:30.34 (69110441)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69136700)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.fileName|”customMetadata/Profi (23 more) …”|0x68e2f535
    08:11:30.34 (69161895)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:25
    08:11:30.34 (69167695)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69190054)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.fullName|”Profile_Setting.TEST (5 more) …”|0x68e2f535
    08:11:30.34 (69352956)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69374415)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.id|null|0x68e2f535
    08:11:30.34 (69400367)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69418714)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.lineNumber|null|0x68e2f535
    08:11:30.34 (69439711)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:107
    08:11:30.34 (69447569)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69469289)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.problem|”Profile_Setting__mdt (87 more) …”|0x68e2f535
    08:11:30.34 (69492317)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
    08:11:30.34 (69498075)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69510841)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.problemType|0x574894ed|0x68e2f535
    08:11:30.34 (69534607)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (69541909)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69559598)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.success|false|0x68e2f535
    08:11:30.34 (69681284)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
    08:11:30.34 (69700517)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
    08:11:30.34 (69746798)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (69756043)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69781997)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.changed|true|0x78871517
    08:11:30.34 (69797954)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69815777)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.columnNumber|null|0x78871517
    08:11:30.34 (69831852)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69847262)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.componentType|null|0x78871517
    08:11:30.34 (69863177)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (69870216)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69890956)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.created|false|0x78871517
    08:11:30.34 (69909951)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69915514)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69945195)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.createdDate|”2019-05-26T07:11:30.935Z”|0x78871517
    08:11:30.34 (69962588)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (69969791)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (69986241)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.deleted|false|0x78871517
    08:11:30.34 (70002294)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:11
    08:11:30.34 (70012878)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (70031594)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.fileName|”package.xml”|0x78871517
    08:11:30.34 (70045837)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:11
    08:11:30.34 (70053285)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (70071190)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.fullName|”package.xml”|0x78871517
    08:11:30.34 (70085817)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (70101261)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.id|null|0x78871517
    08:11:30.34 (70115408)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (70130783)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.lineNumber|null|0x78871517
    08:11:30.34 (70146727)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (70162541)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.problem|null|0x78871517
    08:11:30.34 (70179737)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (70195382)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.problemType|null|0x78871517
    08:11:30.34 (70211070)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (70218258)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (70235092)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.success|true|0x78871517
    08:11:30.34 (70247583)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
    08:11:30.34 (70253358)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
    08:11:30.34 (70317327)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
    08:11:30.34 (70343061)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
    08:11:30.34 (70528339)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.componentFailures|[{“changed”:false,”componentType”:”CustomMetadata”,”created”:false,”createdDate”:”2019-05-26T07:11:30.925Z”,”deleted”:false,”fileName”:”customMetadata/Profi (23 more) …”,”fullName”:”Profile_Setting.TEST (5 more) …”,”problem”:”Profile_Setting__mdt (87 more) …”,”problemType”:”0x574894ed”,”success”:false}]|0x14ca6dfc
    08:11:30.34 (70586949)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
    08:11:30.34 (70597253)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
    08:11:30.34 (70678789)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.componentSuccesses|[{“changed”:true,”created”:false,”createdDate”:”2019-05-26T07:11:30.935Z”,”deleted”:false,”fileName”:”package.xml”,”fullName”:”package.xml”,”success”:true}]|0x14ca6dfc
    08:11:30.34 (70716566)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
    08:11:30.34 (70725259)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (72299784)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.messages|[{“changed”:false,”componentType”:”CustomMetadata”,”created”:false,”createdDate”:”2019-05-26T07:11:30.925Z”,”deleted”:false,”fileName”:”customMetadata/Profi (23 more) …”,”fullName”:”Profile_Setting.TEST (5 more) …”,”problem”:”Profile_Setting__mdt (87 more) …”,”problemType”:”0x574894ed”,”success”:false},{“changed”:true,”created”:false,”createdDate”:”2019-05-26T07:11:30.935Z”,”deleted”:false,”fileName”:”package.xml”,”fullName”:”package.xml”,”success”:true}]|0x78e908ab
    08:11:30.34 (72407738)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
    08:11:30.34 (72471339)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (72506008)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.details|0x14ca6dfc|0x78e908ab
    08:11:30.34 (72555526)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (72565548)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (72600083)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.done|true|0x78e908ab
    08:11:30.34 (72628116)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (72653708)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.errorMessage|null|0x78e908ab
    08:11:30.34 (72678430)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (72702057)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.errorStatusCode|null|0x78e908ab
    08:11:30.34 (72734052)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (72743354)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (72762704)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.ignoreWarnings|false|0x78e908ab
    08:11:30.34 (72791163)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (72801543)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (72830343)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.lastModifiedDate|”2019-05-26T07:11:31.000Z”|0x78e908ab
    08:11:30.34 (72858592)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
    08:11:30.34 (72865927)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (72891464)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.numberComponentErrors|1|0x78e908ab
    08:11:30.34 (72910092)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
    08:11:30.34 (72917272)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (72938121)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.numberComponentsDeployed|0|0x78e908ab
    08:11:30.34 (72955239)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
    08:11:30.34 (72962481)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (72979183)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.numberComponentsTotal|1|0x78e908ab
    08:11:30.34 (72999752)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (73006889)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (73024332)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.rollbackOnError|true|0x78e908ab
    08:11:30.34 (73046811)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:56
    08:11:30.34 (73053618)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (73076546)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.startDate|”2019-05-26T07:11:30.000Z”|0x78e908ab
    08:11:30.34 (73095803)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (73112566)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.stateDetail|null|0x78e908ab
    08:11:30.34 (73131948)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
    08:11:30.34 (73139164)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (73155078)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.status|0x6b7e690d|0x78e908ab
    08:11:30.34 (73175542)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (73183144)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (73199846)|VARIABLE_ASSIGNMENT|[EXTERNAL]|this.success|false|0x78e908ab
    08:11:30.34 (73639377)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:5
    08:11:30.34 (73722541)|SYSTEM_METHOD_ENTRY|[8]|DeployCallbackQueueable.DeployCallbackQueueable()
    08:11:30.34 (73735823)|STATEMENT_EXECUTE|[8]
    08:11:30.34 (73757367)|SYSTEM_METHOD_EXIT|[8]|DeployCallbackQueueable
    08:11:30.34 (73776273)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:12
    08:11:30.34 (73786438)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
    08:11:30.34 (73794409)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:3
    08:11:30.34 (73814407)|METHOD_ENTRY|[1]|01p4J000008ljBX|CreateUpdateMetadataUtils.CreateUpdateMetadataUtils()
    08:11:30.34 (73829123)|STATEMENT_EXECUTE|[1]
    08:11:30.34 (73854360)|STATEMENT_EXECUTE|[1]
    08:11:30.34 (73860901)|METHOD_EXIT|[1]|CreateUpdateMetadataUtils
    08:11:30.34 (73873218)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
    08:11:30.34 (73880833)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:96
    08:11:30.34 (73954687)|VARIABLE_SCOPE_BEGIN|[16]|this|Metadata.DeployCallbackQueueable|true|false
    08:11:30.34 (74093585)|VARIABLE_ASSIGNMENT|[16]|this|{}|0x67a1ed58
    08:11:30.34 (74114116)|VARIABLE_SCOPE_BEGIN|[16]|callback|Metadata.DeployCallback|true|false
    08:11:30.34 (74148773)|VARIABLE_ASSIGNMENT|[16]|callback|{}|0xcf3a730
    08:11:30.34 (74166045)|VARIABLE_SCOPE_BEGIN|[16]|result|Metadata.DeployResult|true|false
    08:11:30.34 (74825409)|VARIABLE_ASSIGNMENT|[16]|result|{“canceledBy”:”000000000000000″,”checkOnly”:false,”completedDate”:”2019-05-26T07:11:31Z”,”createdBy”:”0054J000000vzkk”,”createdByName”:””,”createdDate”:”2019-05-26T07:11:30Z”,”details”:”0x14ca6dfc”,”done”:true,”id”:”0Af4J00000FqesASAR”,”ignoreWarnings”:false,”lastModifiedDate”:”2019-05-26T07:11:31Z”,”messages”:”0x5b1f3fc5″,”numberComponentErrors”:1,”numberComponentsDeployed”:0,”numberComponentsTotal”:1,”rollbackOnError”:true,”startDate”:”2019-05-26T07:11:30Z”,”status”:”0x6b7e690d”,”success”:false}|0x78e908ab
    08:11:30.34 (98910844)|CODE_UNIT_FINISHED|DeployWorker.enqueueApexCallback
    08:11:30.34 (99671137)|EXECUTION_FINISHED

    Thank you!

    • Have you checked if the Metadata Record has been created or not? In the debug it is clear that the Deployment has been queued.

      You can go to setup -> deployment status -> there you can check the status 🙂

      • Hi,
        Yes, I checked!
        the deploy was succeeded (saw it in deployment status), but the Metadata record didn’t created 🙁
        What can make it?

        Thank you!

  3. Hi,
    Yes, I checked!
    the deploy was succeeded (saw it in deployment status), but the Metadata record didn’t created 🙁
    What can make it?

    Thank you!

  4. How to get the Deployment status of deployed Custom Metadata, either success or if it has errors or if it has any issue while deploying .

    • Have you checked below method? In this method, it clearly states about success and error

      public void handleResult(Metadata.DeployResult result,
      Metadata.DeployCallbackContext context) {
      if (result.status == Metadata.DeployStatus.Succeeded) {
      // Deployment was successful
      } else {
      // Deployment was not successful
      }
      }

  5. Hello, this is really fab – thanks so much for jotting it all down. It works beautifully. Did you ever happen to put together a unit test class for this? Asking for a friend 🙂

    • Hi Louis,

      Here is the code for the same. In the below code you need to use your Custom Metadata Name instead of that are there in the code.

      @IsTest
      public class StripeConfigurationServiceTest {

      @IsTest
      public static void configSetupTest(){
          String fullName   = 'Stripe_Config.StripeConfig';
          String label      = 'StripeConfig';
          String values =     '{'+
          '  "Publishable_key__c": "DEMO_KEY",'+
          '  "Secret_key__c": "DEMO_SECRET"'+
          '}';
          Test.startTest();
              StripeConfigurationService.deployConfiguration(fullName, label, values);
          Test.stopTest();
      }
      @IsTest
      public static void CreateUpdateMetadataUtilsTest(){
      
          CreateUpdateMetadataUtils metadata = new CreateUpdateMetadataUtils();
          Test.startTest();
              metadata.handleResult(new Metadata.DeployResult(), new Metadata.DeployCallbackContext());
          Test.stopTest();
      }
      

      }

  6. The content is protected, i can not copy the to my salesforce org …. then what is the use of your article… to make show off ?

    • Content and article are not for show-off. Many people are copying the same and claiming it as their own and that is why we have to make those ptotected.. However, the code has been updated. Please check

  7. Not sure if I’m missing something but where in the article does it mention how to update an existing custom metadata type? Great article by the way.

  8. Hello, I need to get whether the update is successful in real time, because I always call it from LWC page, so I need this method to return whether the update is successful to the front page. I tried to call it directly, but I could not get whether the update is successful. May I ask whether this method is supported?

      • When I try to update the existing metadata I get the following message:
        System.HandledException: Cannot deploy metadata with duplicate fullName YGN_Portal_Value__mdt.Communicatieadviseur for entities of type: CustomMetadata

        It does make sense it gives a duplication error because the value is already existing, I would expect this record to be handled as update but I get above message. Can u help me out?

        • If the record is already present inside the system it will always update because behind the scene it is deploying the metadata records. However if you have duplicate values in the CSV file then it will throw the error.

  9. Can we create custom metadata type records using apex via community site using guest user profile. Tried searching for it but did not found any documentation. Currently trying that from community portal and the deployment status is in pending status only for long and it is not going to either success or failure, its just present in the pending queue. And when tried with sys admin the deployment is immediate.
    If it is not possible via guest user profile, then what approach will you suggest to store these values , specially authentication tokens from the callout ( as you have done in paypal integration video of yours).

    Thanks

  10. I copied same code by creating the Apex class and its related test class and got below error after executing test class:

    – “Metadata cannot be deployed from within a test”

    Are you sure the code is working correctly on test class ?

    • Yes. When we did posted the blog post we tested and made sure it’s working fine. There are chances that some changes were introduce by Salesforce in the latest releases.

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from Panther Schools

Subscribe now to keep reading and get access to the full archive.

Continue reading