I'm fairly new to custom development/coding in general. I've created some Stock__c records in my playground and am trying to update their price using an Http callout to IEX Cloud API. What I can't figure out is how to correctly pass data to the apex class to fetch and update their prices. My end goal is to automate this process so their price is updated every hour or something like that. Research just keeps confusing me and I could use some pointers/advice on the approach.
Apex Class (SOQL here is probably wrong, but for debug purposes it seems to work when using hardcoded Ids)
public class HttpStockQuote {
@future(callout=true)
public static void getQuotes() {
// Get the stock
Stock__c stock = [select id, Ticker__c, Quote__c from Stock__c where Ticker__c <> null];
String url = 'https://cloud.iexapis.com/stable/stock/' + stock.Ticker__c + '/quote/latestPrice?token=pk_xxxxxxxxxx';
System.debug(url);
// Make HTTP callout
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint(url);
request.setMethod('GET');
HttpResponse response = http.send(request);
// Assign new price
String newquote = response.getBody();
System.debug('New Quote');
System.debug(newquote);
// Update records
stock.Quote__c = decimal.valueOf(response.getBody());
update stock;
System.debug(stock);
}
}
Trigger (probably need to be using Trigger.New somewhere but when I pass it to the method, I get incorrect signature void getQuotes(List) error)
trigger GetStockQuoteTrigger on Stock__c (before insert, before update) {
HttpStockQuote.getQuotes();
}
Poke holes in this and tell me what is needed to make this work. I've ran into 'Callout from triggers are currently not supported' error as well as the List errors but I just cannot get past this. Open to all suggestions/advice.