I'm working on an integration to get the information on the price and the market cap from CryptoCompare I was thinking to get the information by placing the values one by one and then perform a future callout for this I created a trigger:

trigger AfterInsertCrypto on Crypto_Price__c (after insert) {
    if (trigger.isInsert && !System.isFuture() && !System.isBatch()){

This trigger will send the information to a method in a class to get the id for the record after inserting the record:

public class Get_Crypto_Coin {
    public static void GetRecord(List<Crypto_Price__c > triggerNew){
             List<Id> irIds = new List<Id>();
        for(Crypto_Price__C irs : triggerNew){

Then it will send the id to a future callout method to perform the callout and save the information in a wrapper:

     @future(callout = true)
        public static void GetCryptoInfo(List<ID> irIds){
            List<Crypto_Price__C> UpdateRecord = new List<Crypto_Price__C>();
            List<Crypto_Price__C > RecordCreated = [Select Crypto_Currency_Name__c,Asset_Price__c,Asset_Market_Cap__c from Crypto_Price__C WHERE ID IN :irIds];
            for(Crypto_Price__C APR :RecordCreated){
                if(APR.Asset_Price__c == null & APR.Asset_Market_Cap__c == null){
        CryptoCompare__mdt cryptoC = CryptoCompare__mdt.getInstance('CryptoCompareAPI');        
        String CryptoName = APR.Crypto_Currency_Name__c;
        String CryptoURL1 = cryptoC.CryptoCompareURL1__c;
        String CryptoURL2 = cryptoC.CryptoCompareURL2__c; 
        String url = CryptoURL1+CryptoName+CryptoURL2;
                HttpRequest req = new HttpRequest();
               Http http = new Http();
              HttpResponse res = http.send(req);
            String requestBody = res.getBody();
            requestBody = 
   Single_Callout single = (Single_Callout) JSON.deserialize(requestBody, Single_Callout.class);

The doc for the API that I'm using is This one to get all the information and pass the values to the wrapper, but what I noticed if I created the wrapper using another callout with another Cryptocurrency name using AdminBooster the values for the wrapper are going to be for that cryptocurrency, so I tried to replace the name of the values using replace but it did not work since the values are different: enter image description here

Is there a way to make a dynamic wrapper base on the values that are coming from the body of the callout and with those values change where they are going to be stored in order to upsert the record that was inserted from the beginning?

The wrapper class that was created from AdminBooster:

global  class Single_Callout{
    global cls_RAW RAW {get;set;}
    global cls_DISPLAY DISPLAY {get;set;}
    global class cls_RAW {
        global cls_BTC BTC {get;set;}
    global class cls_BTC {
        global cls_USD USD {get;set;}
    global class cls_USD {
        global String FROMSYMBOL {get;set;} //Ƀ
        global String TOSYMBOL {get;set;}   //$
        global String MARKET {get;set;} //CryptoCompare Index
        global String PRICE {get;set;}  //$ 16,572.1
        global String LASTUPDATE {get;set;} //Just now
        global String LASTVOLUME {get;set;} //Ƀ 0.00004571
        global String LASTVOLUMETO {get;set;}   //$ 0.7575
        global String LASTTRADEID {get;set;}    //1669585226.7842147
        global String VOLUMEDAY {get;set;}  //Ƀ 13,028.9
        global String VOLUMEDAYTO {get;set;}    //$ 215,431,099.4
        global String VOLUME24HOUR {get;set;}   //Ƀ 15,197.6
        global String VOLUME24HOURTO {get;set;} //$ 251,103,614.2
        global String OPENDAY {get;set;}    //$ 16,451.6
        global String HIGHDAY {get;set;}    //$ 16,587.2
        global String LOWDAY {get;set;} //$ 16,444.2
        global String OPEN24HOUR {get;set;} //$ 16,506.3
        global String HIGH24HOUR {get;set;} //$ 16,588.9
        global String LOW24HOUR {get;set;}  //$ 16,379.9
        global String LASTMARKET {get;set;} //Kraken
        global String VOLUMEHOUR {get;set;} //Ƀ 369.40
        global String VOLUMEHOURTO {get;set;}   //$ 6,119,348.6
        global String OPENHOUR {get;set;}   //$ 16,553.1
        global String HIGHHOUR {get;set;}   //$ 16,574.5
        global String LOWHOUR {get;set;}    //$ 16,550.6
        global String TOPTIERVOLUME24HOUR {get;set;}    //Ƀ 15,197.6
        global String TOPTIERVOLUME24HOURTO {get;set;}  //$ 251,103,614.2
        global String CHANGE24HOUR {get;set;}   //$ 65.77
        global String CHANGEPCT24HOUR {get;set;}    //0.40
        global String CHANGEDAY {get;set;}  //$ 120.51
        global String CHANGEPCTDAY {get;set;}   //0.73
        global String CHANGEHOUR {get;set;} //$ 19.00
        global String CHANGEPCTHOUR {get;set;}  //0.11
        global String CONVERSIONTYPE {get;set;} //direct
        global String CONVERSIONSYMBOL {get;set;}   //
        global String SUPPLY {get;set;} //Ƀ 19,218,456.0
        global String MKTCAP {get;set;} //$ 318.49 B
        global String MKTCAPPENALTY {get;set;}  //0 %
        global String CIRCULATINGSUPPLY {get;set;}  //Ƀ 19,218,456.0
        global String CIRCULATINGSUPPLYMKTCAP {get;set;}    //$ 318.49 B
        global String TOTALVOLUME24H {get;set;} //Ƀ 292.14 K
        global String TOTALVOLUME24HTO {get;set;}   //$ 4.84 B
        global String TOTALTOPTIERVOLUME24H {get;set;}  //Ƀ 291.88 K
        global String TOTALTOPTIERVOLUME24HTO {get;set;}    //$ 4.84 B
        global String IMAGEURL {get;set;}   ///media/37746251/btc.png
    global class cls_DISPLAY {
        global cls_BTC BTC {get;set;}

Or the only way is to specify from the beginning what is the cryptocurrency that is going to be used since the API can get up to 45 cryptocurrencies per call? since I'm using this API URL:


Where is the BTC, you can place BTC,VCX,... separated with a comma and at the end, you can change the USD for any other currency that you want the conversion I was able to get the callouts from groups of 45 but the class is large and so the Wrapper and the Json but I wanted to try to get then one by one using only the name, any idea will be appreciated.


You must log in to answer this question.

Browse other questions tagged .