The out of box Salesforce integration provided by HubSpot falls short when migrating activities. All activities from HubSpot are inserted as Tasks in Salesforce with a “Task Subtype” of Task. As explained in a previous post there are a handful of Task Subtypes and they dictate how a Task is presented in the activity feed.
Unfortunately a Salesforce flow, even a before save flow, is not capable of making the update to Task Subtype when the record is coming in through the integration. The only option in this case is a simple, before insert trigger. The one below assumes Types of “Call” and “Email” are present, translation of Types could easily be added if required. The trigger assigns the Task “Type” value in to the “Task Subtype” field.
trigger HubSpotTaskSubType on Task (before insert) {
// Reassigns the Task SubType of HubSpot generated Tasks
for (Task task : Trigger.new) {
if(task.Type == ‘Call’ || task.Type == ‘Email’){
task.TaskSubtype = task.Type;
}
}
}
To pass this to production a test class is required, here’s one that provides 100% coverage.
@isTest
public class TaskTest {
@isTest
public static void testTaskCall() {
// Create a test Task with subtype Call
Task callTask = new Task(
Subject = ‘Test Call’,
TaskSubtype = ‘Call’,
Type = ‘Call’,
Status = ‘Completed’
);
// Insert the test Task
insert callTask;
// Retrieve the inserted Task
Task insertedTask = [SELECT Id, Subject, TaskSubtype, Status FROM Task WHERE Id = :callTask.Id];
// Assert the Task subtype is Call
System.assertEquals(‘Call’, insertedTask.TaskSubtype);
}
@isTest
public static void testTaskEmail() {
// Create a test Task with subtype Email
Task emailTask = new Task(
Subject = ‘Test Email’,
TaskSubtype = ‘Email’,
Type = ‘Email’,
Status = ‘Completed’
);
// Insert the test Task
insert emailTask;
// Retrieve the inserted Task
Task insertedTask = [SELECT Id, Subject, TaskSubtype, Status FROM Task WHERE Id = :emailTask.Id];
// Assert the Task subtype is Email
System.assertEquals(‘Email’, insertedTask.TaskSubtype);
}
}
LIMITATIONS: This does not account for HubSpot Meetings, which is most appropriately represented in Salesforce as an “Event”. The translation isn’t as simple as changing a single field, rather an entirely new Event record would need to be created. The original Task created by the integration would need to be deleted all of which could be done in a Salesforce flow.
Leave a comment