<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>flows &#8211; Hamza Siddiqui</title>
	<atom:link href="https://www.mhamzas.com/blog/tag/flows/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mhamzas.com</link>
	<description>4x Salesforce MVP &#124; 26x Certified &#124; Salesforce App &#38; System Architect</description>
	<lastBuildDate>Fri, 22 Jan 2021 11:08:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
<site xmlns="com-wordpress:feed-additions:1">233526040</site>	<item>
		<title>Flow: Create/Update CustomMetadata</title>
		<link>https://www.mhamzas.com/blog/2021/01/22/flow-create-update-custommetadata/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=flow-create-update-custommetadata</link>
					<comments>https://www.mhamzas.com/blog/2021/01/22/flow-create-update-custommetadata/#respond</comments>
		
		<dc:creator><![CDATA[hamza]]></dc:creator>
		<pubDate>Fri, 22 Jan 2021 11:04:20 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[apex]]></category>
		<category><![CDATA[flows]]></category>
		<guid isPermaLink="false">https://www.mhamzas.com/?p=3221</guid>

					<description><![CDATA[As of now, you can GET custom metadata records in flows but you cannot create or update them. Using this invocable class you can create/update custom metadata records in Flows. You can access the repository here: https://github.com/mhamzas/Flow-Create-Update-Custom-Metadata The code is self explanatory <br /><a href="https://www.mhamzas.com/blog/2021/01/22/flow-create-update-custommetadata/" class="more-link btn btn-primary">Read More</a>]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image"><img decoding="async" src="https://pbs.twimg.com/media/EsUm8qbXcAIjnSP?format=png&amp;name=small" alt="Image"/></figure>



<p>As of now, you can GET custom metadata records in flows but you cannot create or update them.</p>



<p>Using this invocable class you can create/update custom metadata records in Flows.</p>



<p><strong>You can access the repository here:</strong></p>



<p><a href="https://github.com/mhamzas/Flow-Create-Update-Custom-Metadata">https://github.com/mhamzas/Flow-Create-Update-Custom-Metadata</a></p>



<p>The code is self explanatory but I have tried my best to do better commenting for others to understand what&#8217;s going on here.</p>



<pre class="wp-block-code"><code>/**
 * @description       : This invocable class will allow you to update/create customMetadata using Flow/Process Builder.
 * @author            : M Hamza Siddiqui @ mhamzas.com
 * @group             : Cloudjunction Advisors, Inc.
 * @last modified on  : 01-21-2021
 * @last modified by  : M Hamza Siddiqui @ mhamzas.com
 * Modifications Log 
 * -----------------
 * Ver   Date         Author                             		Modification
 * 1.0   01-22-2021   M Hamza Siddiqui @ mhamzas.com		   Initial Version
**/
global class UpdateCMD implements Metadata.DeployCallback {

    /*An invocable variable used as input or output variables in the process builder*/
    global class ActionRequest {
        @InvocableVariable(required = true)
        public List&lt;sObject&gt; data;
    }
    //This invocable method is used for processing the business by taking the input from process builder/flow
    @InvocableMethod(label = 'Create/Update Custom Metadata')
        global static void invokeService(List &lt;ActionRequest&gt; requests) {
          for (ActionRequest requestObj: requests) {
              //Accessing the values from process builder/flow when record is inserted
              for(sObject obj : requestObj.data){
                  //System.debug('requestObj.sObject@@:' + obj);
                  //System.debug('requestObj.ObjectType@@:' + obj.getSObjectType());
                  // Getting all the Populated fields in a Map
                  Map&lt;String, Object&gt; fieldsToValue = obj.getPopulatedFieldsAsMap();
                  Map&lt;String, Object&gt; metadataFieldValueMap = new Map&lt;String, Object&gt;();
                  String MetadataDevName; // To Store Custom Metadata Record API/Developer name
                  String MetadataLabel; // To Store Custom Metadata Label name
                  // Looping on all the populated fields
                  for (String fieldName : fieldsToValue.keySet()){
                      System.debug('field name is ' + fieldName + ', value is ' + fieldsToValue.get(fieldName));
                      // We don't want to add system fields to the Map for update, so here is some simple logic
                      if(fieldName == 'Label'){
                          MetadataLabel = (String)fieldsToValue.get(fieldName);
                      } else if(fieldName == 'DeveloperName'){
                          MetadataDevName = (String)fieldsToValue.get(fieldName);
                      } else if(fieldName != 'Id' &amp;&amp; fieldName != 'Language' &amp;&amp; fieldName != 'MasterLabel' &amp;&amp; fieldName != 'NamespacePrefix' &amp;&amp; fieldName != 'QualifiedApiName') {
                          // Populating Map for Processing later
                          metadataFieldValueMap.put(fieldName, fieldsToValue.get(fieldName));
                      }
                  }
                  
                  System.debug('Label is ' + MetadataLabel + '&amp; DeveloperName is ' + MetadataDevName);
                  // Making sure to have either Label or Developer Name for the CMD record to process
                  if(String.isBlank(MetadataDevName) &amp;&amp; String.isBlank(MetadataLabel)){
                      throw createCustomException('Make sure to add "Label" attribute in assignemnt for Create and "DeveloperName" for update.');
                  } else { 
                      //if MetadataDevName available, which means the record exists already - Processing UPDATE
                      if(!String.isBlank(MetadataDevName)){
                          UpdateCMD.updateCustomMetadata(String.valueof(obj.getSObjectType()),MetadataDevName, MetadataLabel,metadataFieldValueMap);
                      } else { // Creating a new Custom Metadata record
                          //if ID not available - CREATE
                          UpdateCMD.createCustomMetadata(String.valueof(obj.getSObjectType()), MetadataLabel, metadataFieldValueMap);
                      }
                  }
                  // END
              }
          }
    }
    
    /* Custom Metadata Deploy Methods */
    /* ============================================================*/
    //Inteface method 
    public void handleResult(Metadata.DeployResult result, Metadata.DeployCallbackContext context) {
        if (result.status == Metadata.DeployStatus.Succeeded) {
            //Success
            System.debug('Success Result-' + result);
        } else {
            //Failed
            System.debug('Failed Result-' + result);
            throw createCustomException(String.valueof(result));
        }
    }
     
    //Create Custom Metadata record
    public static void createCustomMetadata(String metdataName, String label, Map&lt;String, Object&gt; metadataFieldValueMap){
        String recordDevName = label.replaceAll(' ', '_');
        Metadata.CustomMetadata cMetadata = new Metadata.CustomMetadata();
        cMetadata.fullName = metdataName + '.' + recordDevName;
        cMetadata.label = label;
         
        for(String key : metadataFieldValueMap.keySet()){
            Metadata.CustomMetadataValue cMetadataValue = new Metadata.CustomMetadataValue();
            cMetadataValue.Field = key;
            cMetadataValue.Value = metadataFieldValueMap.get(key); 
            cMetadata.values.add(cMetadataValue);
        }
         
        Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
        mdContainer.addMetadata(cMetadata);
        UpdateCMD callback = new UpdateCMD();
        Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, callback);
    }
     
    //Update Custom Metadata record
    public static void updateCustomMetadata(String metdataName, String recordDevName, String label, Map&lt;String, Object&gt; metadataFieldValueMap){
        Metadata.CustomMetadata cMetadata = new Metadata.CustomMetadata();
        cMetadata.fullName = metdataName + '.' + recordDevName;
        cMetadata.label = label;
         
        for(String key : metadataFieldValueMap.keySet()){
            Metadata.CustomMetadataValue cMetadataValue = new Metadata.CustomMetadataValue();
            cMetadataValue.Field = key;
            cMetadataValue.Value = metadataFieldValueMap.get(key); 
            cMetadata.values.add(cMetadataValue);
        }
         
        Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
        mdContainer.addMetadata(cMetadata);
        UpdateCMD callback = new UpdateCMD();
        Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, callback);
    }

    /* Flow Exception Handling */
    /* ============================================================*/
    public class CustomException extends Exception {}
    
    static CustomException createCustomException(String message) {
        CustomException ex = new CustomException(message);
        ex.setMessage(message);
        return ex;
    }
}</code></pre>



<p>Happy Coding!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.mhamzas.com/blog/2021/01/22/flow-create-update-custommetadata/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3221</post-id>	</item>
		<item>
		<title>Trailblazer Karachi Admin Group &#8211; April Virtual Meetup</title>
		<link>https://www.mhamzas.com/blog/2020/05/29/trailblazer-karachi-admin-group-april-virtual-meetup/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=trailblazer-karachi-admin-group-april-virtual-meetup</link>
					<comments>https://www.mhamzas.com/blog/2020/05/29/trailblazer-karachi-admin-group-april-virtual-meetup/#respond</comments>
		
		<dc:creator><![CDATA[hamza]]></dc:creator>
		<pubDate>Fri, 29 May 2020 18:10:24 +0000</pubDate>
				<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[appexchange]]></category>
		<category><![CDATA[flows]]></category>
		<category><![CDATA[salesforce]]></category>
		<category><![CDATA[trailblazergroups]]></category>
		<guid isPermaLink="false">https://www.mhamzas.com/?p=3121</guid>

					<description><![CDATA[Trailblazer Karachi Admin Group &#8211; April Virtual Meetup Whether you&#8217;re an experienced Administrator, just getting started, want to learn more, we invite you to join in the fun. Mansoor Ahmed showed us some top free apps from app exchange for our daily <br /><a href="https://www.mhamzas.com/blog/2020/05/29/trailblazer-karachi-admin-group-april-virtual-meetup/" class="more-link btn btn-primary">Read More</a>]]></description>
										<content:encoded><![CDATA[
<p><strong>Trailblazer Karachi Admin Group &#8211; April Virtual Meetup</strong> Whether you&#8217;re an experienced Administrator, just getting started, want to learn more, we invite you to join in the fun. </p>



<p><strong>Mansoor Ahmed</strong> showed us some<strong> top free apps from app exchange</strong> for our daily use. </p>



<p><strong>Sandhya Bajaj</strong> helped us get started with <strong>Salesforce flows</strong> </p>



<p><strong>Presentations :</strong> Flows : https://docs.google.com/presentation/d/1RP-P8-fhRry0GAZeLuNkin3mC1rPcOwp1YX1_r7TJP8/edit?usp=sharing</p>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<div class="jetpack-video-wrapper"><iframe title="Trailblazer Karachi Admin Group – April Virtual Meetup" width="640" height="360" src="https://www.youtube.com/embed/sds6tHqBrwc?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
</div></figure>
]]></content:encoded>
					
					<wfw:commentRss>https://www.mhamzas.com/blog/2020/05/29/trailblazer-karachi-admin-group-april-virtual-meetup/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3121</post-id>	</item>
	</channel>
</rss>
