YUCEL
YUCEL

Talking about my Salesforce.com and MuleSoft experience

Edgar Moran
Author

Software Engineer, passionate for tech stuff video and photography, Salesforce and Mulesoft developer

Share


Our Newsletter


Subscribe to get new post notifications.

* indicates required

Tags


Twitter


YUCEL

How to create a Process Builder Flow with Apex code

Edgar MoranEdgar Moran

Develop applications for customers is not a really easy task, you need to provide guidance and intuitive interfaces.

So I had this requirement:

  • To have a page where the customer could configure a flow (as a workflow or similar)
  • Generate templates (not email templates but similar) where I can substitute the content based on merge fields
  • finally send a callout to a server when the condition is met with the message in my template previously configured.

Almost everything was possible with the Metadata API (https://github.com/financialforcedev/apex-mdapi) so now I'll share a little bit what I did as I would like to separate the functionality at some point and made a separate post by feature.

To make this happen I developed a separate class that allows me to separate step by step what I need in my process Builder flow. and then other where I can invoke the process and set the parameters as needed.

Here is the class:


public with sharing class flow_handler {
	public flow_handler() {}

	public static List<MetadataService.FlowActionCall> getFlowActionCallArray(String flowNameString,String sobjectSelected){

		List<Metadataservice.FlowMetadataValue> list_processMetadataValues = new List<Metadataservice.FlowMetadataValue>();
        List<Metadataservice.FlowMetadataValue> list_processMetadataValues_flow = new List<Metadataservice.FlowMetadataValue>();
        List<Metadataservice.FlowMetadataValue> list_processMetadataValues_object = new List<Metadataservice.FlowMetadataValue>();
    
        
        /*
            VAR #1 
         */

        MetadataService.FlowElementReferenceOrValue metadataReference1 = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference1.stringValue                                 = 'Record Id';

        MetadataService.FlowElementReferenceOrValue metadataReference2 = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference2.stringValue                                 = 'String';
        MetadataService.FlowElementReferenceOrValue metadataReference3 = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference3.booleanValue                                 = true;
        MetadataService.FlowElementReferenceOrValue metadataReference4 = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference4.numberValue                                 = 0.0;
        MetadataService.FlowElementReferenceOrValue metadataReference5 = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference5.stringValue                                 = sobjectSelected;

        MetadataService.FlowElementReferenceOrValue metadataReference6 = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference6.stringValue                                 = 'Reference';
        
        Metadataservice.FlowMetadataValue metadatavalue1               = new Metadataservice.FlowMetadataValue();
        metadatavalue1.name                                            = 'leftHandSideLabel';
        metadatavalue1.value                                           = metadataReference1;
        Metadataservice.FlowMetadataValue metadatavalue22              = new Metadataservice.FlowMetadataValue();
        metadatavalue22.name                                           = 'dataType';
        metadatavalue22.value                                          = metadataReference2;
        Metadataservice.FlowMetadataValue metadatavalue33               = new Metadataservice.FlowMetadataValue();
        metadatavalue33.name                                            = 'isRequired';
        metadatavalue33.value                                           = metadataReference3;
        Metadataservice.FlowMetadataValue metadatavalue44               = new Metadataservice.FlowMetadataValue();
        metadatavalue44.name                                            ='maxOccurs';
        metadatavalue44.value                                           = metadataReference4;
        Metadataservice.FlowMetadataValue metadatavalue55               = new Metadataservice.FlowMetadataValue();
        metadatavalue55.name                                            = 'objectType';
        metadatavalue55.value                                           = metadataReference5;
        Metadataservice.FlowMetadataValue metadatavalue66               = new Metadataservice.FlowMetadataValue();
        metadatavalue66.name                                            = 'rightHandSideType';
        metadatavalue66.value                                           = metadataReference6;

        list_processMetadataValues.add(metadatavalue1);
        list_processMetadataValues.add(metadatavalue22);
        list_processMetadataValues.add(metadatavalue33);
        list_processMetadataValues.add(metadatavalue44);
        list_processMetadataValues.add(metadatavalue55);
        list_processMetadataValues.add(metadatavalue66);

        /*
        
            VAR #2
         */

        MetadataService.FlowElementReferenceOrValue metadataReference1_flow = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference1_flow.stringValue                                 = 'FlowName';

        MetadataService.FlowElementReferenceOrValue metadataReference2_flow = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference2_flow.stringValue                                 = 'String';

        MetadataService.FlowElementReferenceOrValue metadataReference3_flow = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference3_flow.booleanValue                                 = false;
        MetadataService.FlowElementReferenceOrValue metadataReference4_flow = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference4_flow.numberValue                                 = 1.0;
        MetadataService.FlowElementReferenceOrValue metadataReference5_flow = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference5_flow.stringValue                                 = sobjectSelected;

        MetadataService.FlowElementReferenceOrValue metadataReference6_flow = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference6_flow.stringValue                                 = 'String';
        
        Metadataservice.FlowMetadataValue metadatavalue1_flow               = new Metadataservice.FlowMetadataValue();
        metadatavalue1_flow.name                                            = 'leftHandSideLabel';
        metadatavalue1_flow.value                                           = metadataReference1_flow;
        Metadataservice.FlowMetadataValue metadatavalue22_flow              = new Metadataservice.FlowMetadataValue();
        metadatavalue22_flow.name                                           = 'dataType';
        metadatavalue22_flow.value                                          = metadataReference2_flow;
        Metadataservice.FlowMetadataValue metadatavalue33_flow               = new Metadataservice.FlowMetadataValue();
        metadatavalue33_flow.name                                            = 'isRequired';
        metadatavalue33_flow.value                                           = metadataReference3_flow;
        Metadataservice.FlowMetadataValue metadatavalue44_flow              = new Metadataservice.FlowMetadataValue();
        metadatavalue44_flow.name                                            ='maxOccurs';
        metadatavalue44_flow.value                                           = metadataReference4_flow;
        Metadataservice.FlowMetadataValue metadatavalue55_flow               = new Metadataservice.FlowMetadataValue();
        metadatavalue55_flow.name                                            = 'objectType';
        metadatavalue55_flow.value                                           = metadataReference5_flow;
        Metadataservice.FlowMetadataValue metadatavalue66_flow               = new Metadataservice.FlowMetadataValue();
        metadatavalue66_flow.name                                            = 'rightHandSideType';
        metadatavalue66_flow.value                                           = metadataReference2_flow;

        Metadataservice.FlowMetadataValue metadatavalueflowname_flow               = new Metadataservice.FlowMetadataValue();
        metadatavalueflowname_flow.name                                            = 'leftHandSideLabel';
        metadatavalueflowname_flow.value                                           = metadataReference1_flow;

        list_processMetadataValues_flow.add(metadatavalue1_flow);
        list_processMetadataValues_flow.add(metadatavalue22_flow);
        list_processMetadataValues_flow.add(metadatavalue33_flow);
        list_processMetadataValues_flow.add(metadatavalue44_flow);
        list_processMetadataValues_flow.add(metadatavalue55_flow);
        list_processMetadataValues_flow.add(metadatavalue66_flow);



        /*
        
            VAR #3
         */

        MetadataService.FlowElementReferenceOrValue metadataReference1_object = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference1_object.stringValue                                 = 'Object';

        MetadataService.FlowElementReferenceOrValue metadataReference2_object = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference2_object.stringValue                                 = 'String';

        MetadataService.FlowElementReferenceOrValue metadataReference3_object = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference3_object.booleanValue                                 = false;
        MetadataService.FlowElementReferenceOrValue metadataReference4_object = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference4_object.numberValue                                 = 1.0;
        MetadataService.FlowElementReferenceOrValue metadataReference5_object = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference5_object.stringValue                                 = sobjectSelected;

        MetadataService.FlowElementReferenceOrValue metadataReference6_object = new Metadataservice.FlowElementReferenceOrValue();
        metadataReference6_object.stringValue                                 = 'String';
        
        Metadataservice.FlowMetadataValue metadatavalue1_object               = new Metadataservice.FlowMetadataValue();
        metadatavalue1_object.name                                            = 'leftHandSideLabel';
        metadatavalue1_object.value                                           = metadataReference1_object;
        Metadataservice.FlowMetadataValue metadatavalue22_object              = new Metadataservice.FlowMetadataValue();
        metadatavalue22_object.name                                           = 'dataType';
        metadatavalue22_object.value                                          = metadataReference2_object;
        Metadataservice.FlowMetadataValue metadatavalue33_object               = new Metadataservice.FlowMetadataValue();
        metadatavalue33_object.name                                            = 'isRequired';
        metadatavalue33_object.value                                           = metadataReference3_object;
        Metadataservice.FlowMetadataValue metadatavalue44_object              = new Metadataservice.FlowMetadataValue();
        metadatavalue44_object.name                                            ='maxOccurs';
        metadatavalue44_object.value                                           = metadataReference4_object;
        Metadataservice.FlowMetadataValue metadatavalue55_object               = new Metadataservice.FlowMetadataValue();
        metadatavalue55_object.name                                            = 'objectType';
        metadatavalue55_object.value                                           = metadataReference5_object;
        Metadataservice.FlowMetadataValue metadatavalue66_object               = new Metadataservice.FlowMetadataValue();
        metadatavalue66_object.name                                            = 'rightHandSideType';
        metadatavalue66_object.value                                           = metadataReference2_object;

        Metadataservice.FlowMetadataValue metadatavalueflowname_object               = new Metadataservice.FlowMetadataValue();
        metadatavalueflowname_object.name                                            = 'leftHandSideLabel';
        metadatavalueflowname_object.value                                           = metadataReference1_object;

        list_processMetadataValues_object.add(metadatavalue1_object);
        list_processMetadataValues_object.add(metadatavalue22_object);
        list_processMetadataValues_object.add(metadatavalue33_object);
        list_processMetadataValues_object.add(metadatavalue44_object);
        list_processMetadataValues_object.add(metadatavalue55_object);
        list_processMetadataValues_object.add(metadatavalue66_object);


        List<MetadataService.FlowActionCallInputParameter> list_inputParamters = new List<MetadataService.FlowActionCallInputParameter>();
        

        MetadataService.FlowActionCallInputParameter inputParameter            = new MetadataService.FlowActionCallInputParameter();
        MetadataService.FlowElementReferenceOrValue inputParameter_value       = new Metadataservice.FlowElementReferenceOrValue();
        inputParameter.name                                                    = 'RecordId';
        inputParameter_value.elementReference                                  = 'myVariable_current.Id'; 
        inputParameter.value                                                   = inputParameter_value; 
        inputParameter.processMetadataValues                                   = list_processMetadataValues;   
        list_inputParamters.add(inputParameter);



        
        MetadataService.FlowActionCallInputParameter inputParameter_flow            = new MetadataService.FlowActionCallInputParameter();
        MetadataService.FlowElementReferenceOrValue inputParameter_value_flow       = new Metadataservice.FlowElementReferenceOrValue();
        inputParameter_flow.name                                                    = 'flowName';
        inputParameter_value_flow.stringValue                                       = flowNameString; 
        inputParameter_flow.value                                                   = inputParameter_value_flow; 
        inputParameter_flow.processMetadataValues                                   = list_processMetadataValues_flow;   
        list_inputParamters.add(inputParameter_flow);


        MetadataService.FlowActionCallInputParameter inputParameter_object            = new MetadataService.FlowActionCallInputParameter();
        MetadataService.FlowElementReferenceOrValue inputParameter_value_object             = new Metadataservice.FlowElementReferenceOrValue();
        inputParameter_object.name                                                    = 'objectName';
        inputParameter_value_object.stringValue                                       = sobjectSelected; 
        inputParameter_object.value                                                   = inputParameter_value_object; 
        inputParameter_object.processMetadataValues                                   = list_processMetadataValues_object;   
        list_inputParamters.add(inputParameter_object);
        
    


        List<Metadataservice.FlowMetadataValue> list_processMetadataValues_actioncall = new List<Metadataservice.FlowMetadataValue>();
        Metadataservice.FlowMetadataValue processMetadataValueActionCall = new Metadataservice.FlowMetadataValue();
        MetadataService.FlowElementReferenceOrValue metadataReferenceactioncallmetadata = new Metadataservice.FlowElementReferenceOrValue();
        metadataReferenceactioncallmetadata.stringValue                                 = 'mssgdirect_evaluateCondiitonHandler';

        processMetadataValueActionCall.name = 'apexSelection';
        processMetadataValueActionCall.value = metadataReferenceactioncallmetadata;
        list_processMetadataValues_actioncall.add(processMetadataValueActionCall);


        List<MetadataService.FlowActionCall> actionCallsArray = new List<MetadataService.FlowActionCall>();
        MetadataService.FlowActionCall actioncall             = new  MetadataService.FlowActionCall();        
        actioncall.name                                       = 'myRule_1_A1';
        actioncall.label                                      = 'invoca clase de apex';
        actioncall.locationX                                  = 100;
        actioncall.locationY                                  = 200;
        actioncall.actionName                                 = 'mssgdirect_evaluateCondiitonHandler';
        actioncall.actionType                                 = 'apex';
        actioncall.inputParameters                            = list_inputParamters;
        actioncall.processMetadataValues                      = list_processMetadataValues_actioncall;

        actionCallsArray.add(actioncall);

        return actionCallsArray;
	}

	public static List<MetadataService.FlowCondition> getFlowConditions(List<mssgdirect_applicationHandler.Condition> conditions){

		List<Metadataservice.FlowMetadataValue> list_metadataValue = new List<Metadataservice.FlowMetadataValue>();
		List<MetadataService.FlowCondition> listConditions         = new List<MetadataService.FlowCondition>();
		MetadataService.FlowElementReferenceOrValue elementValue1  = new Metadataservice.FlowElementReferenceOrValue();
        elementValue1.stringValue = 'String';

		//LOOP OVER CONDITIONS TO GENERATE AS MANY WE NEDD
		for(mssgdirect_applicationHandler.Condition condition_record:conditions){
			
			Metadataservice.FlowMetadataValue metadatavalue           = new MetadataService.FlowMetadataValue();
			metadatavalue.name                                        = 'operatorDataType';
			metadatavalue.value                                       = elementValue1;
			list_metadataValue.add(metadatavalue);
			
			Metadataservice.FlowMetadataValue metadatavalue2          = new MetadataService.FlowMetadataValue();
			metadatavalue2.name                                       = 'inputDataType';
			metadatavalue2.value                                      = elementValue1;
			list_metadataValue.add(metadatavalue2);
			
			Metadataservice.FlowMetadataValue metadatavalue3          = new MetadataService.FlowMetadataValue();
			metadatavalue3.name                                       = 'leftHandSideType';
			metadatavalue3.value                                      = elementValue1;
			list_metadataValue.add(metadatavalue3);
			
			Metadataservice.FlowMetadataValue metadatavalue4          = new MetadataService.FlowMetadataValue();
			metadatavalue4.name                                       = 'rightHandSideType';
			metadatavalue4.value                                      = elementValue1;
			list_metadataValue.add(metadatavalue4);        
			
			MetadataService.FlowElementReferenceOrValue valueCriteria = new Metadataservice.FlowElementReferenceOrValue();
			valueCriteria.stringValue                                 = condition_record.value;
			
			
			MetadataService.FlowCondition condition                   = new MetadataService.FlowCondition();
			condition.processMetadataValues                           = list_metadataValue;
			condition.operator                                        = condition_record.condition;
			condition.rightValue                                      = valueCriteria;
			condition.leftValueReference                              = 'myVariable_current.'+condition_record.field;    
			listConditions.add(condition);
		}

        return listConditions;
	}

	public static List<MetadataService.FlowRule> getFlowRules(List<mssgdirect_applicationHandler.Condition> conditionList){
		 /**
         * ::::: RULES ::::::
         */
        Metadataservice.FlowConnector flowConnectorinRule = new Metadataservice.FlowConnector();
        flowConnectorinRule.targetReference               = 'myRule_1_A1';

        List<MetadataService.FlowRule> list_rules = new List<MetadataService.FlowRule>();
        MetadataService.FlowRule rule             = new Metadataservice.FlowRule();
        rule.name                                 = 'myRule_1';
        rule.conditionLogic                       = 'and';
        rule.conditions                           = mssgdirect_flowHandler.getFlowConditions(conditionList);
        rule.connector                            = flowConnectorinRule;
        rule.label                                = 'Valida criterios';
        list_rules.add(rule);

        return list_rules;
	}

	public static List<Metadataservice.FlowDecision> getFlowDesitions(List<mssgdirect_applicationHandler.Condition> conditionList){
		 /*
            ::::: decitions :::::
         */

        List<Metadataservice.FlowDecision> list_desicions = new List<Metadataservice.FlowDecision>();
        Metadataservice.FlowDecision flowDecision         = new Metadataservice.FlowDecision();
        flowDecision.name                                 = 'myDecision';
        flowDecision.label                                = 'Primary Decision';
        flowDecision.locationX                            = 50;
        flowDecision.locationY                            = 0;
        flowDecision.defaultConnectorLabel                = 'default';
        flowDecision.rules                                = mssgdirect_flowHandler.getFlowRules(conditionList);
        
        list_desicions.add(flowDecision);

        return list_desicions;
	}

	public static List<MetadataService.FlowAssignment> getFlowAssigments(){
		         /*
            ::::: ASSIGMENTs :::::
         */
        Metadataservice.FlowConnector flowConnector          = new Metadataservice.FlowConnector();
        flowConnector.targetReference                        = 'myDecision';

        List<MetadataService.FlowAssignment> list_assigments = new List<MetadataService.FlowAssignment>();
        MetadataService.FlowAssignment assigment             = new MetadataService.FlowAssignment();
        assigment.name                                       = 'myVariable_waitStartTimeAssignment';
        assigment.label                                      = 'myVariable_waitStartTimeAssignment';
        assigment.locationX                                  = 0;
        assigment.locationY                                  = 0;
        assigment.connector                                  = flowConnector;

        List<MetadataService.FlowAssignmentItem> listAssigmentItem = new List<MetadataService.FlowAssignmentItem>();
        MetadataService.FlowAssignmentItem assigmentItem           = new MetadataService.FlowAssignmentItem();
        
        MetadataService.FlowElementReferenceOrValue elementValue   = new Metadataservice.FlowElementReferenceOrValue();
        elementValue.dateTimeValue                                 = Datetime.now();
        
        assigmentItem.assignToReference                            = 'myVariable_waitStartTimeVariable';
        assigmentItem.operator                                     = 'Assign';
        assigmentItem.value                                        = elementValue;
        listAssigmentItem.add(assigmentItem);
        
        assigment.assignmentItems                                  = listAssigmentItem;
        list_assigments.add(assigment);
        return list_assigments;
	}

	public static List<Metadataservice.FlowMetadataValue> getFlowProcessMetadataValues(String sfdcObject){
		 /*
            ::::: METADATA VALKUES :::::
         */
        List<Metadataservice.FlowMetadataValue> flow_processMetadataValuesList = new List<Metadataservice.FlowMetadataValue>();        
        MetadataService.FlowElementReferenceOrValue processMetatdataElement1 = new Metadataservice.FlowElementReferenceOrValue();
        Metadataservice.FlowMetadataValue meta1                              = new Metadataservice.FlowMetadataValue();
        processMetatdataElement1.stringValue                                 = sfdcObject;        
        meta1.name                                                           = 'ObjectType';
        meta1.value                                                          = processMetatdataElement1;
        flow_processMetadataValuesList.add(meta1);

        MetadataService.FlowElementReferenceOrValue processMetatdataElement2 = new Metadataservice.FlowElementReferenceOrValue();
        Metadataservice.FlowMetadataValue meta2                              = new Metadataservice.FlowMetadataValue();
        processMetatdataElement2.elementReference                            = 'myVariable_current';        
        meta2.name                                                           = 'ObjectVariable';
        meta2.value                                                          = processMetatdataElement2;
        flow_processMetadataValuesList.add(meta2);

        /*MetadataService.FlowElementReferenceOrValue processMetatdataElement3 = new Metadataservice.FlowElementReferenceOrValue();
        Metadataservice.FlowMetadataValue meta3                              = new Metadataservice.FlowMetadataValue();
        processMetatdataElement3.elementReference                            = 'myVariable_old';        
        meta3.name                                                           = 'OldObjectVariable';
        meta3.value                                                          = processMetatdataElement3;
        flow_processMetadataValuesList.add(meta3);*/

        MetadataService.FlowElementReferenceOrValue processMetatdataElement4 = new Metadataservice.FlowElementReferenceOrValue();
        Metadataservice.FlowMetadataValue meta4                              = new Metadataservice.FlowMetadataValue();
        processMetatdataElement4.stringValue                                 = 'onAllChanges';        
        meta4.name                                                           = 'TriggerType';
        meta4.value                                                          = processMetatdataElement4;
        flow_processMetadataValuesList.add(meta4);

        return flow_processMetadataValuesList;
	}

	public static List<MetadataService.FlowVariable> getFlowVariables(String sfdcObject){
		/*
            ::::: VARIABLES :::::
         */
        List<MetadataService.FlowVariable> list_variables = new List<MetadataService.FlowVariable>();        
        MetadataService.FlowVariable variable = new  MetadataService.FlowVariable();
        variable.name                         = 'myVariable_current';
        variable.dataType                     = 'SObject';
        variable.isCollection                 = false;
        variable.isInput                      = true;
        variable.isOutput                     = true;
        variable.objectType                   = sfdcObject;
        list_variables.add(variable);

        MetadataService.FlowVariable variable2 = new  MetadataService.FlowVariable();
        variable2.name                         = 'myVariable_old';
        variable2.dataType                     = 'SObject';
        variable2.isCollection                 = false;
        variable2.isInput                      = true;
        variable2.isOutput                     = true;
        variable2.objectType                   = sfdcObject;
        list_variables.add(variable2);

        MetadataService.FlowElementReferenceOrValue datetime_elementReference = new Metadataservice.FlowElementReferenceOrValue();
        datetime_elementReference.dateTimeValue = Datetime.now();
        
        MetadataService.FlowVariable variable3  = new  MetadataService.FlowVariable();
        variable3.name                          = 'myVariable_waitStartTimeVariable';
        variable3.dataType                      = 'DateTime';
        variable3.isCollection                  = false;
        variable3.isInput                       = false;
        variable3.isOutput                      = false;
        variable3.value                         = datetime_elementReference;
        list_variables.add(variable3);  

        return list_variables;
	}


}

And here how I invoke the class

global static String createFlow(String object_list,String sfdcObjectName){
        String original_object = sfdcObjectName;
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader                = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId      = UserInfo.getSessionId();

        List<Condition> deserializedConditions = (List<Condition>)JSON.deserialize(object_list, List<Condition>.class);
        
        MetadataService.Flow flow  = new MetadataService.Flow();
        flow.description           = 'MSSGDirect, '+sfdcObjectName;
        flow.interviewLabel        = 'mssgdirect_'+sfdcObjectName.replace('__c','')+'-1_'+sfdcObjectName.replace('__c','');
        String fullNameobj         = sfdcObjectName.replace('mssgdirect__','');
        flow.fullName              = 'mssgdirect_'+Date.today().Year()+''+Date.today().Month()+''+Date.today().Day()+Datetime.now().Hour()+Datetime.now().Minute()+'_'+fullNameobj.replace('__c','')+'-1';
        flow.label                 = 'mssgdirect_'+Date.today().Year()+''+Date.today().Month()+''+Date.today().Day()+Datetime.now().Hour()+Datetime.now().Minute()+'_'+sfdcObjectName.replace('__c','');
        flow.processType           = 'Workflow';
        flow.startElementReference = 'myVariable_waitStartTimeAssignment';
        flow.processMetadataValues = mssgdirect_flowHandler.getFlowProcessMetadataValues(original_object);
        flow.variables             = mssgdirect_flowHandler.getFlowVariables(original_object);
        flow.assignments           = mssgdirect_flowHandler.getFlowAssigments();
        flow.actionCalls           = mssgdirect_flowHandler.getFlowActionCallArray(flow.label,original_object);
        flow.decisions             = mssgdirect_flowHandler.getFlowDesitions(deserializedConditions);//here an array of conditions


        return handleSaveResults(service.createMetadata(new List<MetadataService.Metadata> { flow })[0]);
    }

This is the result in process builder:

Screen-Shot-2018-01-24-at-10.11.28-AM

So far this is only the general concept, I'll write other post with the separate components involved and update this again, but I guess with this you'll get the idea.

Edgar Moran
Author

Edgar Moran

Software Engineer, passionate for tech stuff video and photography, Salesforce and Mulesoft developer

Comments