A long time ago in a galaxy far, far away…
Or in 2013 to be exact, Salesforce acquired the arguably fledgling marketing automation product known as ExactTarget. Since renaming to Marketing Cloud and rolling this into the Salesforce family, Salesforce have introduced and refined their Marketing Cloud Connect managed package, which allows for integrating Marketing Cloud with Sales & Service Cloud CRM.
Along with improvements to this integration have come many overall improvements and additional features. One such improvement has been with the MobileConnect product, under Mobile Studio. Unfortunately however, integration between Sales Cloud and the MobileConnect side of Marketing Cloud is still lacking, to the point where even the Mobile Opt Out field in Sales Cloud, that is a part of the Marketing Cloud Connect package, is not integrated at all with MobileConnect.
Many businesses now integrating Sales and Marketing Cloud via the Connect package will be using the Sales Cloud CRM as their source of truth for email and mobile subscribers. So in this scenario we need to tightly handle subscriber opt out status between the Marketing Cloud and the CRM. As mentioned, unfortunately while the Email Opt Out field does get updated via the Connect integration from Marketing Cloud to Sales Cloud when an email subscriber unsubscribes, the same cannot be said for MobileConnect. Mobile subscribers will be opted out in MobileConnect but this is not reflected on their source contact record in Sales Cloud.
While it is possible to build a scheduled automation in Automation Studio to run the appropriate SQL and SSJS to perform a mass update of the Mobile Opt Out field on Contacts in Sales Cloud, this can be achieved in real-time…
AMPScript to the rescue!
This is where some Jedi mind tricks, or creative AMPScript can be implemented in the STOP keyword message(s) within the MobileConnect administration, to update the related Sales Cloud contact record.
MobileConnect does not expose the Subscriber Key directly in AMPScript and so we need to lookup the Subscriber Key, which when integrating with Sales Cloud will be the Contact ID or Lead ID. This ID will be needed to perform the update on the source contact record. In this code example we will be looking up the Subscriber Key from the Contact_Salesforce synchronized data extension based on the Mobile number.
More information about Synchronized Data Extensions here: https://help.salesforce.com/articleView?id=mc_cab_data_integration_for_your_account_with_synchronized_data_sources.htm&type=5
Note that this lookup method requires that the Mobile number in this data extension is in the correctly normalized format, with country code and no leading zero (i.e 61438123456). In some instances the Mobile numbers within Sales Cloud will not be in a normalized state, and are later transformed via SQL into another separate “contact” data extension by a Marketing Cloud automation. Use whichever data extension in your environment has the proper mobile number format for the lookup.
%%[ /* lookup the base subscriber key for this mobile contact directly from the synchronized DE */ var @subscriberKey, @result set @subscriberKey = Lookup('Contact_Salesforce', 'Id', 'MobilePhone', MOBILE_NUMBER) /* update the contact mobile opt-out field in Sales Cloud */ set @result = UpdateSingleSalesforceObject('Contact', @subscriberKey, 'et4ae5__HasOptedOutOfMobile__c', 'true') IF @result == 0 THEN ]%% There was an error processing your request. Please try again. %%[ ELSE ]%% You have now been unsubscribed from all SMS messages. %%[ ENDIF ]%%
That’s it, pretty cool! This can be modified or extended to update any fields on the source contact record as needed.