In today’s digital landscape, managing customer data efficiently is crucial for successful marketing campaigns. Salesforce Marketing Cloud provides robust APIs that allow developers to interact with contact data programmatically. In this blog post, we’ll explore how to use the REST API in CRM to delete contacts from your Marketing Cloud account. Whether you’re cleaning up outdated records or converted leads records, understanding the process is essential. Let’s dive in!
Use case:
- When lead records are populated in SFMC’s synchronized data extension, a _ContactKey field is added to store the LeadId or Converted ContactId.
- If an email is sent to a subscriber using the lead which syncs from CRM to SFMC (either by using filter data extensions or using a query to store the lead data in a standard data extension).
- A record is created with SubscriberKey (LeadId), and EmailAddress in the All Subscriber list in SFMC.
- If the same lead is converted, the _ContactKey attribute will be changed to Converted ContactId.
- Suppose an email is sent to the same Lead, in that case, a new record will be created with a new SubscriberKey (Converted ContactId) but the subscriber record with SubscriberKey (LeadId) will not be deleted.
- At the same time in CRM, once a lead is converted all the Individual Email Result records will be archived with the lead record without transferring all of it to the converted contact.
Prerequisite :
- Should have Salesforce CRM Enterprise or above edition.
- Salesforce CRM should be integrated to SFMC using Marketing Cloud Connect.
Problem Statement :
- Minimum 2 subscriber records will be saved in all subscriber and in all contacts when a email is sent before and after to a lead.
- Consumes contact storage in the long run.
- Lead IERs are archived after the lead
After the solution implementation :
- No duplication of subscriber data in SFMC.
- Saves contact storage in SFMC.
- Historic IERs from lead will be transferred to contact to be accessible.
Solution:
A flow will be created in CRM that triggers when a lead is converted and transfers all the Individual Email Results to Contact, while asynchronously deleting the lead from the SFMC account while creating an auth connection using a package in SFMC, it’s a complete codeless solution, that uses the following elements-
- Flow Builder (CRM).
- Named Credentials (CRM).
- External Credentials (CRM).
- A permission set with Named and External credential access (CRM) Integration Package (SFMC)
Steps to the Solution:
- Create a package in SFMC for authentication with credentials.
- Go to Setup -> Platform Tools -> Apps -> Installed Packages.
- Click on New.
- Add a Name and description of your choice in the “New Package Details”.
- Add all the permissions needed (depending on how and what the package will be used for), for now, add delete permission for contacts and click on Save.
NOTE: Create the package in the Business Unit connected with the targeted CRM instance.
- Turn on the Contact Deletion in SFMC.
- Go to Contact Builder > Contacts Configuration.
- Click on the “On” toggle under the “Contact Delete” section, then select 1 or 0 in the “Contact Deletion Settings” drop-down, and click on Save.
This will allow the contact deletion throughout the SFMC Account
- Create an External credential in SFMC.
- Go to Setup > Security > Named Credentials > External Credentials.
- Click on the New button and add the details as shown in the image below (get the Auth URL from SFMC’s Package that was created in step 1), and click on Save.
- Create Named Credential to be used in the flow for authentication.
- Go to Setup > Security > Named Credentials, and click on the “New” button.
- Add all the details as shown in the below image sample, get the REST URI form the package created in step 1, and only replace the “YOUR_REST_URL” with the key provided in the package URI. Add “External Credential” and “Client Certificate” that was created in previous steps.
- Tick all the options under Callout Options and click on the Save button.
- Create a Permission Set to give access to the user for External Credentials.
- Create a record-triggered Flow on the Lead object that triggers when a lead is converted.
Add the IER transfer logic in the flow to run immediately and SFMC Lead delete logic will be on the Asynchronous path, which will include apex action for http callout.
In results, without writing code this will delete Converted Lead in SFMC and transfer all the Individual Email Results to Converted Contact in CRM.
Hope this helps, please do share and comment.