Skip to content
← All guides

Which HubSpot custom code examples should you start from?

The custom code jobs HubSpot uses as examples, and the Turbyn recipes that match them: phone numbers, owner rotation, duplicate contacts, and closing tasks.

Turbyn · Published · Updated

The short answer

HubSpot's custom code docs point to weighted lead rotation, international phone formatting, archiving contacts, deduplicating contacts, and completing tasks on a closed deal. Start with one of those jobs, confirm the inputs and outputs, and only then add API calls or extra libraries.

HubSpot’s custom code documentation names five jobs as the shape of the feature:

  • Weighted lead rotation with custom weights
  • Formatting international phone numbers
  • Archiving or deleting contacts
  • Deduplicating contacts
  • Completing all tasks for a closed deal

Those are the right first searches if you are looking for “HubSpot custom code examples.” Each one is a rule the standard workflow buttons do not express, with a result a later step has to use.

Match the example to a recipe

Turbyn ships these as editable actions rather than as snippets to paste into HubSpot’s editor. The native action and a Turbyn action do not share a runtime. The job is the same.

Job HubSpot uses as an example A Turbyn recipe for that job
Format an international phone number Normalize phone numbers
Rotate or assign by a weight you control Distribute work by owner weights
Deduplicate contacts Merge duplicate contacts
Finish the tasks hanging off a record Complete associated tasks
Archive a record and the dependents you scope Archive a record with scoped dependents

Phone formatting is the cleanest first run. It has an input, a deterministic output, and a visible failure when the number is not valid. Owner weights are the assignment version of the same idea: the table of rules lives in the action, and the workflow only has to store the owner that comes back.

Merging, archiving, and completing tasks write to the CRM. Run those against a test record first. HubSpot’s own tester applies native custom code to the record you select, and a Turbyn action that calls HubSpot will do the same once you point it at a real record.

What a useful example includes

A snippet that only logs a property is not yet an example you can enroll. The version worth copying has four parts:

  1. The fields the workflow must pass in.
  2. The rule, including the invalid case.
  3. Named outputs a later step can branch on.
  4. A note about anything the code writes, so a retry cannot do it twice.

HubSpot custom code actions is the overview of the native step. Limitations are the reason a sample that works once can still fail on a large enrollment: 20 seconds, 128 MB, and only the libraries HubSpot lists.

Build the one you actually need

If the job is not in the table, start from the recipe library or from a blank action. The first publish should be the smallest version that returns one output. Custom code without Data Hub explains how that action is added to a workflow when you are not using HubSpot’s native editor. The quickstart is connect HubSpot and publish.

Sources and references

Source documentation checked for this update. Availability can vary by subscription and account.

Questions from this guide

The custom code action documentation names a set of programmable-automation examples and links HubSpot's use-case library. The GitHub repository HubSpot/sample-workflow-custom-code is the public sample project those docs sit next to in search.

Continue reading