Skip to content
← BlogSalesforce · 3 min read

Building a dynamic integration between Salesforce and the Formula 1 public API using Apex. This post dives into how we handled pagination, ensured proper JSON deserialization into typed Apex classes, and dealt with inconsistencies across different endpoints. 🧩

SalesforceApex3 min

And here we are, for the second part of our adventure storing Formula 1 data inside Salesforce! 😀

I’ll try not to make this post too technical, so I don’t bore you too much—promise I’ll keep it light! 😅(But if you are a nerd — like me — you can follow this other post where I go some deep inside implementation —Nerd)

First, let’s start with the goals we achieved in this phase:

  • ✅ Named Credentials
  • ✅ Apex exception handling when the API doesn’t respond
  • ✅ Connecting to the API and fetching data for a chosen year
  • ✅ Storing the received data into specific Salesforce objects
  • ✅ Visualizing the inserted data within our app
  • ✅ Creating an app dedicated solely to Formula 1
  • ✅ Studying the API’s data model to implement a proper Salesforce data model with the correct relationships between objects

Step 1 – Studying the Endpoint 🔍

  • We began by analyzing what the API returns, which endpoints exist, and which ones we wanted to use in this first phase.
  • After evaluation, we decided to use the Season endpoint, as it provides most of the data we need — race results, drivers, teams, and everything essential.

Step 2 – Creating the necessary objects 🗂️

  • After studying the API, we designed the Salesforce objects needed to store all relevant data from the API
  • Once the object structure was solid, we moved on to API implementation

Step 3 – API Configuration ⚙️

  • Following Salesforce best practices, we created a Named Credential to securely store the API connection
  • Then we built an Apex class: F1APIService, which holds all the logic for integrating Salesforce with the API. It contains all possible API calls.
  • We can now perform direct queries for specific drivers, teams, etc.
  • The code workflow looks like this:
    1. Receive the season from the Flow
    2. Fetch race and sprint data from the API
    3. Convert the data into Salesforce records (races, drivers, etc.)
    4. Insert or update these records in Salesforce
    5. Return data back to the Flow
    6. In case of errors, return an error message to stop the Flow

Step 4 – Creating a ScreenFlow 🔄

  • We created a Screen Flow as the user interface for interacting with the API. In this flow, the user can search for any season they want.
  • Once the user triggers the search, the following records get created:
    • Season
    • Races
    • Race Results
    • Drivers
    • Driver Constructors
    • Constructors
    • Circuits

After all that, we reached the first version of our Formula 1 app! 🏁

It’s not perfect yet, but it’s getting there.

Right now, you can view all key info related to each season — everything is available inside the Lightning Record Pages for each object! ⚡


Next Steps 🛠️:

  • Implement a better way to identify whether a Race record is a race or a sprint — right now you have to open the record and check the “Type” field
  • Automate updates for the current season with weekend race results
  • Build a dynamic calendar showing upcoming races 📅
  • Create report types and dashboards to compare data between races, drivers, teams, seasons, and more 📊
Written by Ricardo SimõesSalesforce + AI developer · Portugal / Remote
Questions about this post, or just want to talk Salesforce and AI? Happy to chat.
0Comments

Comments

Loading animation
→Keep readingAll posts →