We have a lookup already in place for Incoming SMS and SMS History for Campaigns. The incoming SMS is not attached to the Campaigns directly because their is no phone number present in a Campaign. However, outgoing SMS are attached to the Campaigns and they can be seen under the SMS History related list.


You can achieve incoming SMS lookup on Campaign by using flows and Process Builder.This will be help you to pull reports on Incoming responses on a particular Campaign if the Incoming SMS gets attached to that particular campaign.You can follow the below steps for complete details of the same:


Pre-requisites:


Create a lookup field on Incoming SMS with SMS History named "SMS History lookup" (in order to fetch the details of Campaign name from on Incoming SMS only if their is an outgoing SMS attached and Campaign lookup field on SMS History is not blank. We will also be using this field in our flow and process builder)


I have implemented this use case in my org and below are the steps to achieve the same:


A: RECORD LOOKUP


1. Go to setup -> flows

2. Open a flow and create two Variables varIncomingMobileNumber and varSMSHistoryId (you can find the option of creating variable under Resources tab in flow) 

3. Drag a Record lookup screen on the canvas. As soon as you drop the record lookup screen fill in the details.Name the record lookup (Lookup SMS History on Incoming SMS)

4. Select SMS History object in the lookup field (as we want to create lookup of SMS History, you will find it under Custom)

5. Select the criteria that smagicinteract_Campaign__c (Campaign field on SMS History) is not null and store smagicinteract_PhoneNumber__c in a variable varIncomingMobileNumber.

6. Sort results by CreatedDate so that we can create lookup of Campaign with the most recent SMS History record where Campaign value is notNull.

7. Return the Id of that SMS History and store it in a variable varSMSHistoryId.

8. Click Ok and mark this as the start point of your flow.


Please refer the below screen shot for details of the same:


ZnOuzQzwHiAIVoM3k3LFBx6TnQAaBmMrKg.png

B : RECORD UPDATE


1. Drag and drop the Record Update screen on the canvas and name it as Update SMS History on Incoming SMS.

2. Select the object on which you want to update the fields that is Incoming SMS.

3. Select the criteria that the SMS History lookup field should not be blank

4. Update the value of SMS History lookup field with the varSMSHistoryId (Id of SMS History) and click Ok.

5. Save the flow and activate it (you will see the flow in process builder only if it is activated)


Please refer below screen shot for details:


ZIelrAFZWeclJikkjQGe_qIA7jUueCxLzQ.png


Process Builder1 (Update SMS History lookup field on Incoming SMS):


1. Select the object as Incoming SMS

2. Specify the criteria SMS History lookup field on Incoming SMS isNull.


Please refer the below screenshot for details:


3. Select the Action as flows and select the flow which we created earlier from the drop down.

4. Reference the variables in flow mobile number and smshistoryId against Mobile Number and SMS History lookup field on Incoming SMS respectively.


5. Once the above process builder is activated, whenever an incoming SMS is received the SMS History record which is attached to that particular campaign (for which Incoming SMS is                 received) will be fetched.


Process Builder2: (To populate the Campaign lookup on Incoming SMS)


1. Again select the object as Incoming SMS.

2. Select SMS History lookup field os not NULL and click save.

3. Select the action as Update Records in Immediate actions and select the record as Incoming SMS which started the flow as we want to update the field on Incoming SMS.

4. Select the field Campaign (which is already present on Incoming SMS) and reference it with CampignId through SMS History Lookup (lookup field on Incoming SMS) and Save. Activate the flow.


Please refer below screen shot for details:


ya3v_qytQk2VQbQiGB7xteqNQhZRK2tO6Q.png

Once the setup is done test is out by sending an SMS through a  Campaign and reply back. You will the Campaign name gets populated on the Incoming SMS and it is also attached to the Incoming SMS related list on the Campaign.


bJFNwRjy5nmXQkzLOh8rXf3KXmLCrKlFuw.png

Once the Campaign lookup starts working on Incoming SMS you can run a report based on Incoming responses for a particular campaign. Please refer below screen shot for details:


g4vArJtVng97ZxUXfCGxIckzt_qZiBUqTg.png



In case if you sending SMS to the same Campaign members from multiple Campaigns, the incoming SMS gets attached to the Camapign from whcih the SMS was last sent (that is sent recently). To resolve this issue you can follow below steps:


1. Ask users to reply with foreg: YES for Campaign A and 'NO' for Campaign B

2. Mention the criteria as Incoming SMS Text contains YES and SMS History lookup is having lookup Campaign A then only populate       the Campaign lookup field on Incoming SMS with Campaign A else leave it blank and similarly it should be NO and SMS History             campaign lookup should be Campaign B, so that incoming SMS gets  attached to the correct Campaign.