<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
    <actionCalls>
        <name>Email_Action</name>
        <label>Email Action</label>
        <locationX>578</locationX>
        <locationY>1092</locationY>
        <actionName>emailSimple</actionName>
        <actionType>emailSimple</actionType>
        <flowTransactionModel>CurrentTransaction</flowTransactionModel>
        <inputParameters>
            <name>emailAddresses</name>
            <value>
                <elementReference>Recipients</elementReference>
            </value>
        </inputParameters>
        <inputParameters>
            <name>emailSubject</name>
            <value>
                <elementReference>Subject</elementReference>
            </value>
        </inputParameters>
        <inputParameters>
            <name>emailBody</name>
            <value>
                <elementReference>BodyTemplate</elementReference>
            </value>
        </inputParameters>
        <inputParameters>
            <name>sendRichBody</name>
            <value>
                <booleanValue>true</booleanValue>
            </value>
        </inputParameters>
    </actionCalls>
    <actionCalls>
        <name>Split_Errors</name>
        <label>Split Errors</label>
        <locationX>578</locationX>
        <locationY>276</locationY>
        <actionName>InvalidMessageAlertsInvocable</actionName>
        <actionType>apex</actionType>
        <connector>
            <targetReference>Errors_Loop</targetReference>
        </connector>
        <flowTransactionModel>CurrentTransaction</flowTransactionModel>
        <inputParameters>
            <name>errors</name>
            <value>
                <elementReference>$Record.Errors__c</elementReference>
            </value>
        </inputParameters>
        <outputParameters>
            <assignToReference>ErrorsCollection</assignToReference>
            <name>errorsList</name>
        </outputParameters>
    </actionCalls>
    <apiVersion>60.0</apiVersion>
    <assignments>
        <name>ErrorsHtml</name>
        <label>ErrorsHtml</label>
        <locationX>666</locationX>
        <locationY>492</locationY>
        <assignmentItems>
            <assignToReference>ErrorsVar</assignToReference>
            <operator>Add</operator>
            <value>
                <elementReference>EachError</elementReference>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Errors_Loop</targetReference>
        </connector>
    </assignments>
    <assignments>
        <name>Vendor_MTL</name>
        <label>Vendor MTL</label>
        <locationX>842</locationX>
        <locationY>792</locationY>
        <assignmentItems>
            <assignToReference>Vendor</assignToReference>
            <operator>Assign</operator>
            <value>
                <stringValue>MTL</stringValue>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Get_MTL_Config</targetReference>
        </connector>
    </assignments>
    <assignments>
        <name>Vendor_SMF</name>
        <label>Vendor SMF</label>
        <locationX>50</locationX>
        <locationY>792</locationY>
        <assignmentItems>
            <assignToReference>Vendor</assignToReference>
            <operator>Assign</operator>
            <value>
                <stringValue>SMF</stringValue>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Get_SMF_Config</targetReference>
        </connector>
    </assignments>
    <assignments>
        <name>Vendor_Tunespeak</name>
        <label>Vendor Tunespeak</label>
        <locationX>578</locationX>
        <locationY>792</locationY>
        <assignmentItems>
            <assignToReference>Vendor</assignToReference>
            <operator>Assign</operator>
            <value>
                <stringValue>Tunespeak</stringValue>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Get_Tunespeak_Config</targetReference>
        </connector>
    </assignments>
    <assignments>
        <name>Vendor_Wyng</name>
        <label>Vendor Wyng</label>
        <locationX>314</locationX>
        <locationY>792</locationY>
        <assignmentItems>
            <assignToReference>Vendor</assignToReference>
            <operator>Assign</operator>
            <value>
                <stringValue>Wyng</stringValue>
            </value>
        </assignmentItems>
        <connector>
            <targetReference>Get_Wyng_Config</targetReference>
        </connector>
    </assignments>
    <decisions>
        <name>Created_By</name>
        <label>Created By</label>
        <locationX>578</locationX>
        <locationY>684</locationY>
        <defaultConnector>
            <targetReference>Get_Others_Config</targetReference>
        </defaultConnector>
        <defaultConnectorLabel>Default Outcome</defaultConnectorLabel>
        <rules>
            <name>SMF</name>
            <conditionLogic>and</conditionLogic>
            <conditions>
                <leftValueReference>$Record.CreatedBy.Profile.Name</leftValueReference>
                <operator>EqualTo</operator>
                <rightValue>
                    <stringValue>Integration SMF</stringValue>
                </rightValue>
            </conditions>
            <connector>
                <targetReference>Vendor_SMF</targetReference>
            </connector>
            <label>SMF</label>
        </rules>
        <rules>
            <name>Wyng</name>
            <conditionLogic>and</conditionLogic>
            <conditions>
                <leftValueReference>$Record.CreatedBy.Profile.Name</leftValueReference>
                <operator>EqualTo</operator>
                <rightValue>
                    <stringValue>Integration Wyng</stringValue>
                </rightValue>
            </conditions>
            <connector>
                <targetReference>Vendor_Wyng</targetReference>
            </connector>
            <label>Wyng</label>
        </rules>
        <rules>
            <name>Tunespeak</name>
            <conditionLogic>and</conditionLogic>
            <conditions>
                <leftValueReference>$Record.CreatedBy.Profile.Name</leftValueReference>
                <operator>EqualTo</operator>
                <rightValue>
                    <stringValue>Integration Tunespeak</stringValue>
                </rightValue>
            </conditions>
            <connector>
                <targetReference>Vendor_Tunespeak</targetReference>
            </connector>
            <label>Tunespeak</label>
        </rules>
        <rules>
            <name>MTL</name>
            <conditionLogic>and</conditionLogic>
            <conditions>
                <leftValueReference>$Record.CreatedBy.Profile.Name</leftValueReference>
                <operator>EqualTo</operator>
                <rightValue>
                    <stringValue>Integration MTL</stringValue>
                </rightValue>
            </conditions>
            <connector>
                <targetReference>Vendor_MTL</targetReference>
            </connector>
            <label>MTL</label>
        </rules>
    </decisions>
    <environments>Default</environments>
    <formulas>
        <name>Errors</name>
        <dataType>String</dataType>
        <expression>SUBSTITUTE({!$Record.Errors__c}, &quot;, &quot;, &quot;&lt;br/&gt;&quot;)</expression>
    </formulas>
    <formulas>
        <name>LinkToRecord</name>
        <dataType>String</dataType>
        <expression>LEFT($Api.Partner_Server_URL_260, FIND( &apos;/services&apos;, $Api.Partner_Server_URL_260)) &amp; {!$Record.Id}</expression>
    </formulas>
    <formulas>
        <name>NOW</name>
        <dataType>DateTime</dataType>
        <expression>NOW()</expression>
    </formulas>
    <formulas>
        <name>NOW_Text</name>
        <dataType>String</dataType>
        <expression>TEXT(NOW())</expression>
    </formulas>
    <formulas>
        <name>Subject</name>
        <dataType>String</dataType>
        <expression>IF(LEN({!Vendor}) &gt; 0, {!Vendor} + &quot; Invalid Message Received&quot;, &quot;Invalid Message Received&quot;)</expression>
    </formulas>
    <interviewLabel>Invalid Messages Alert Flow {!$Flow.CurrentDateTime}</interviewLabel>
    <label>Invalid Message Alert Flow</label>
    <loops>
        <name>Errors_Loop</name>
        <label>Errors Loop</label>
        <locationX>578</locationX>
        <locationY>384</locationY>
        <collectionReference>ErrorsCollection</collectionReference>
        <iterationOrder>Asc</iterationOrder>
        <nextValueConnector>
            <targetReference>ErrorsHtml</targetReference>
        </nextValueConnector>
        <noMoreValuesConnector>
            <targetReference>Created_By</targetReference>
        </noMoreValuesConnector>
    </loops>
    <processMetadataValues>
        <name>BuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>CanvasMode</name>
        <value>
            <stringValue>AUTO_LAYOUT_CANVAS</stringValue>
        </value>
    </processMetadataValues>
    <processMetadataValues>
        <name>OriginBuilderType</name>
        <value>
            <stringValue>LightningFlowBuilder</stringValue>
        </value>
    </processMetadataValues>
    <processType>AutoLaunchedFlow</processType>
    <recordLookups>
        <name>Get_MTL_Config</name>
        <label>Get MTL Config</label>
        <locationX>842</locationX>
        <locationY>900</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Email_Action</targetReference>
        </connector>
        <filterLogic>and</filterLogic>
        <filters>
            <field>Name</field>
            <operator>EqualTo</operator>
            <value>
                <stringValue>INVALID_MESSAGES_MTL_RECIPIENTS</stringValue>
            </value>
        </filters>
        <object>Config__c</object>
        <outputAssignments>
            <assignToReference>Recipients</assignToReference>
            <field>Value__c</field>
        </outputAssignments>
    </recordLookups>
    <recordLookups>
        <name>Get_Others_Config</name>
        <label>Get Others Config</label>
        <locationX>1106</locationX>
        <locationY>792</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Email_Action</targetReference>
        </connector>
        <filterLogic>and</filterLogic>
        <filters>
            <field>Name</field>
            <operator>EqualTo</operator>
            <value>
                <stringValue>INVALID_MESSAGES_OTHERS_RECIPIENTS</stringValue>
            </value>
        </filters>
        <object>Config__c</object>
        <outputAssignments>
            <assignToReference>Recipients</assignToReference>
            <field>Value__c</field>
        </outputAssignments>
    </recordLookups>
    <recordLookups>
        <name>Get_SMF_Config</name>
        <label>Get SMF Config</label>
        <locationX>50</locationX>
        <locationY>900</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Email_Action</targetReference>
        </connector>
        <filterLogic>and</filterLogic>
        <filters>
            <field>Name</field>
            <operator>EqualTo</operator>
            <value>
                <stringValue>INVALID_MESSAGES_SMF_RECIPIENTS</stringValue>
            </value>
        </filters>
        <object>Config__c</object>
        <outputAssignments>
            <assignToReference>Recipients</assignToReference>
            <field>Value__c</field>
        </outputAssignments>
    </recordLookups>
    <recordLookups>
        <name>Get_Tunespeak_Config</name>
        <label>Get Tunespeak Config</label>
        <locationX>578</locationX>
        <locationY>900</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Email_Action</targetReference>
        </connector>
        <filterLogic>and</filterLogic>
        <filters>
            <field>Name</field>
            <operator>EqualTo</operator>
            <value>
                <stringValue>INVALID_MESSAGES_TUNESPEAK_RECIPIENTS</stringValue>
            </value>
        </filters>
        <object>Config__c</object>
        <outputAssignments>
            <assignToReference>Recipients</assignToReference>
            <field>Value__c</field>
        </outputAssignments>
    </recordLookups>
    <recordLookups>
        <name>Get_Wyng_Config</name>
        <label>Get Wyng Config</label>
        <locationX>314</locationX>
        <locationY>900</locationY>
        <assignNullValuesIfNoRecordsFound>false</assignNullValuesIfNoRecordsFound>
        <connector>
            <targetReference>Email_Action</targetReference>
        </connector>
        <filterLogic>and</filterLogic>
        <filters>
            <field>Name</field>
            <operator>EqualTo</operator>
            <value>
                <stringValue>INVALID_MESSAGES_WYNG_RECIPIENTS</stringValue>
            </value>
        </filters>
        <object>Config__c</object>
        <outputAssignments>
            <assignToReference>Recipients</assignToReference>
            <field>Value__c</field>
        </outputAssignments>
    </recordLookups>
    <start>
        <locationX>56</locationX>
        <locationY>0</locationY>
        <object>Invalid_Message__c</object>
        <recordTriggerType>Create</recordTriggerType>
        <scheduledPaths>
            <connector>
                <targetReference>Split_Errors</targetReference>
            </connector>
            <pathType>AsyncAfterCommit</pathType>
        </scheduledPaths>
        <triggerType>RecordAfterSave</triggerType>
    </start>
    <status>Active</status>
    <textTemplates>
        <name>BodyTemplate</name>
        <isViewedAsPlainText>true</isViewedAsPlainText>
        <text>&lt;ul&gt;
&lt;li&gt;Record: &lt;a href=&quot;{!LinkToRecord}&quot;&gt;{!$Record.Id}&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;User: {!$User.Username}&lt;/li&gt;
&lt;li&gt;Time: {!NOW_Text}&lt;/li&gt;
&lt;li&gt;Errors:&lt;/li&gt;
&lt;ul&gt;{!ErrorsVar}&lt;/ul&gt;
&lt;li&gt;Message:&lt;/li&gt;
&lt;pre&gt;&lt;code&gt;{!$Record.Message__c}&lt;/code&gt;&lt;/pre&gt;
&lt;/ul&gt;</text>
    </textTemplates>
    <textTemplates>
        <name>EachError</name>
        <isViewedAsPlainText>true</isViewedAsPlainText>
        <text>&lt;li&gt;{!Errors_Loop}&lt;/li&gt;</text>
    </textTemplates>
    <variables>
        <name>ErrorsCollection</name>
        <dataType>String</dataType>
        <isCollection>true</isCollection>
        <isInput>false</isInput>
        <isOutput>true</isOutput>
    </variables>
    <variables>
        <name>ErrorsVar</name>
        <dataType>String</dataType>
        <isCollection>false</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
    </variables>
    <variables>
        <name>Recipients</name>
        <dataType>String</dataType>
        <isCollection>false</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
    </variables>
    <variables>
        <name>Vendor</name>
        <dataType>String</dataType>
        <isCollection>false</isCollection>
        <isInput>false</isInput>
        <isOutput>false</isOutput>
    </variables>
</Flow>
