If there are multiple records in your Org which have the same number and you would like the Incoming SMS to be attached to the correct record then we need to add a unique identifier to the Incoming SMS text. Also the incoming SMS text needs to be in a specific format so that we can update the related record fields based on the format. In order to meet this requirement, we need to create a Flow and a Process Builder in the customers' Org. 


In this scenario, the customer wants to update a custom field on Case object. However, there were multiple cases that had the same number as the incoming mobile number so the response was getting attached to the incorrect record.


Following are the steps needed to configure the flow in the customers' Org:

  • Create 4 variables with the type as "Text" and "Input and Output" type. 
  • Next create the Record Lookup in flow which will lookup to the case object based on the criteria that Case Number is equal to one variable. Based on this criteria, store that case's record Id in another variable.
   


  • After saving the record lookup, we need to create a decision where we check that the variable in which we had stored the Case Id is not null.

  • After creating the decision, create 1st record update which will update Case Id on the Incoming SMS case lookup field with the case ID which matches the case number in the SMS Text. While updating the case lookup field we check the criteria if the external Id of the case is equal to third variable.


  • Once, the incoming SMS record is updated or attached to the correct case, we need to update the Incoming SMS text on the related case. In order to do so, we will create another record lookup in the flow.


  • Once the record lookup is created, we need to create the sequence in which the elements need to be triggered. Also, we need to click on the green arrow on the element which will start the flow. This is how the flow looks like after defining the sequence:



After the flow is created and activated, we need to create a process builder from which we will trigger the flow and set the values for the variables. Following are the steps taken to create the process builder for this scenario:

  • The object selected to start the process builder is "Incoming SMS" and the process will be triggered whenever a new Incoming SMS record is created.
  • Enter the criteria based on which the process needs to be triggered in the next step. In this scenario there was no criteria.
  • In the next step, action was selected as flow and the API name of the flow which was created earlier was selected from the list of flows.
  • Lastly, the value for the variables was defined under "Set Flow Variable" section. Here we defined the values for following 3 variables which we used in the flow:
    1.  Variable in which we are storing the Case Number.
    2.  Variable in which we are storing the external Id of the incoming SMS.
    3.  Variable in which we are storing the Incoming SMS text.
After defining the variables, we save the process builder and activate it. This fixed the issue of Incoming SMS getting attached to the incorrect record if there are multiple records with the same number.