A Very Special Episode
If you haven’t heard about the GameStop stock situation then I genuinely don’t know where you’ve been.
And if you’re like me and most of the people I work with, you’ve been checking that ticker roughly every four minutes all week trying to work out when it’s going to the moon.
So I built something so you never have to leave Salesforce to do it. A GME ticker that sits in your utility bar, pulls the current stock price, and refreshes whenever you want it to.
Your salespeople can now stay fully informed without ever alt-tabbing away from your org. You’re welcome.
What’s Actually Going On Here
Silliness aside, this is a genuinely useful pattern and there are three real techniques in it worth stealing:
1. Calling an external API from Apex and getting structured data back.
2. Using a wrapper class to deserialize the JSON response cleanly.
3. Putting a Lightning Web Component in the utility bar, which is a surprisingly underused piece of Salesforce.
Swap “stock price” for “order status” or “shipment tracking” and this is a genuinely useful production pattern.
The Apex Side
public with sharing class StockTickerController
{
@AuraEnabled(cacheable=false)
public static StockQuote getQuote(String ticker)
{
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:StockApi/quote?symbol=' + ticker);
req.setMethod('GET');
HttpResponse res = new Http().send(req);
if (res.getStatusCode() != 200)
{
throw new AuraHandledException('Could not retrieve the quote');
}
return (StockQuote) JSON.deserialize(res.getBody(), StockQuote.class);
}
public class StockQuote
{
@AuraEnabled public String symbol;
@AuraEnabled public Decimal price;
@AuraEnabled public Decimal changePercent;
}
}Three things worth pointing out.cacheable=false is deliberate. A cached method would happily serve you a five minute old price, which rather defeats the purpose. Cacheable methods also can’t do callouts.callout:StockApi is a Named Credential, so your API key isn’t in the code.
Every property on the inner class has @AuraEnabled. Miss one and it silently arrives as undefined in your JavaScript.
The Component
import { LightningElement } from 'lwc';
import getQuote from '@salesforce/apex/StockTickerController.getQuote';
export default class StockTicker extends LightningElement {
quote;
error;
connectedCallback() {
this.refreshQuote();
}
async refreshQuote() {
try {
this.quote = await getQuote({ ticker: 'GME' });
this.error = undefined;
} catch (e) {
this.error = e.body ? e.body.message : 'Something went wrong';
}
}
get isUp() {
return this.quote && this.quote.changePercent > 0;
}
}Note connectedCallback() loading the price before the component renders, which I covered in this quick tip.
An imperative Apex call rather than @wire, because we want to refresh on demand rather than reactively.
Getting It Into The Utility Bar
The bit worth knowing. Add this to your .js-meta.xml:
<targets>
<target>lightning__UtilityBar</target>
</targets>Then Setup → App Manager → Edit your app → Utility Items → Add Utility Item and pick your component.
The utility bar is genuinely underrated. It’s persistent across every page, it’s always one click away, and it’s perfect for anything a user needs constant access to without navigating anywhere. Same targets logic as adding a component to a record page.
Before You Deploy This To Production
Some genuine advice buried under the joke.
Mind your callout limits. 100 per transaction, and a daily API allowance. A ticker every user refreshes constantly adds up faster than you’d think. Consider caching the price in Platform Cache for thirty seconds so a hundred users share one callout.
Handle the API being down. Free stock APIs are exactly as reliable as you’d expect. Fail gracefully rather than showing a stack trace in the utility bar.
Maybe check with your manager. Deploying a stock ticker to the sales team’s org is a decision with, let’s say, cultural implications.
None of this is investment advice, obviously. I’m a Salesforce developer.
Get Coding With The Force Merch!!
We now have a redbubble store setup so you can buy cool Coding With The Force merchandise! Please check it out! Every purchase goes to supporting the blog and YouTube channel.
Get Shirts Here!
Get Cups, Artwork, Coffee Cups, Bags, Masks and more here!
Check Out More Coding With The Force Stuff!
If you liked this post make sure to follow us on all our social media outlets to stay as up to date as possible with everything!
Youtube
Patreon
Github
Facebook
Twitter
Instagram
Salesforce Development Books I Recommend
Advanced Apex Programming
Salesforce Lightning Platform Enterprise Architecture
Mastering Salesforce DevOps
Good Non-SF Specific Development Books:
Clean Code
Clean Architecture