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:
- The fields the workflow must pass in.
- The rule, including the invalid case.
- Named outputs a later step can branch on.
- 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.