63. How does the app relate the incoming messages to record in Salesforce?

There are 2 ways Incoming messages get related to the record in Salesforce.

Whenever you send a message to a new record a Conversation Record gets created. The conversation is Parent Object to SMS History. Once the message is sent it will be attached to that Conversation. If you get a reply from that mobile number we check for Mobile Number and SenderID on the Conversation Object and attach it to the last created Conversation if there is any. If there is no Conversation for the Mobile Number and Sender id combination a new Conversation Record is created.

Whenever a new incoming message is received, we check if this message is a response to existing outgoing messages based on the Phone number and sender id combination. If there is more than one such outgoing message, we consider the response to be for the latest outgoing message. This message is looked up as the previous message. If a previously sent outgoing message is found, we associate the incoming message with the same conversation as the previous outgoing message. If a previous message is not found, we find the number in all objects configured in Object Config and populate a lookup of all such objects. After this, our application applies a logic to identify the primary object to which this message should be associated with. Finally, a conversation is created / associated for the incoming message based on Phone Number, Sender Id, Primary Object, Primary Object Id and User criteria. if an existing conversation exists where all the 5 attributes match the incoming message, it is used to associate the new incoming message. If no such conversation exists, a new conversation is created.

Creation of Conversations: When an Outgoing message is sent if there are no Conversations with the same Mobile number, Sender id, Owner id, Object and record id a new Conversations will get created. If there is an existing Conversation Record the Outgoing message will get attached to it. If any of the value (Mobile number, Sender id, Owner id, Object and record id) changes a new Conversation record will get created. Similarly for the Incoming message when you receive it if there is a Conversation Record with the Mobile number and Sender id it will get attached to it. If there is no Conversation it will create a new one.

Important Announcement!

URGENT! Please register the 10-digit business phone number (e.g. 555-555-5555) that your organization uses to send texts to consumers in the U.S. Failure to register may cause heavy penalties and disruption to all your text messaging communications.