function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nagendra kumar 21nagendra kumar 21 

How to Write a scheduled class to update the Data Conversion Rate at the start of every month.

Hi All, 
please help me developing code or share code who to write apex class for this scenario and how to schedule it.

req - 
1) Fetch the exchange rate (CAN/USD) from some publicly available api using apex
2) Given this exchange rate create a Currency Conversion Record with the correct start date, end date and exchange rate.
3) Run a scheduled job to run (1) and (2) once per month.

thanks 
nagendra
Raj VakatiRaj Vakati
You can call the REst API 

https://developer.salesforce.com/forums/?id=906F00000008xMkIAI
https://salesforce.stackexchange.com/questions/17380/update-conversionrate-in-test-class​​​​​​​
https://th3silverlining.com/2009/11/23/dml-currently-not-allowed/​​​​​​​
https://salesforce.stackexchange.com/questions/175205/manage-datedconversionrate-using-apex?noredirect=1&lq=1​​​​​​​

 
HttpRequest feedRequest = new HttpRequest();
        feedRequest.setEndpoint('callout{Named_Credentials}/services/data/v36.0/sobjects/DatedConversionRate/'+ {idDatedConversion} +'?_HttpMethod=PATCH');
        feedRequest.setBody('{ "ConversionRate" : '+ {rate }+' }');//Rate to be updated            
        feedRequest.setHeader('Content-Type', 'application/json');
        
        feedRequest.setMethod('POST');
        Http http = new Http();
        try
        {
            if(!Test.isRunningTest()){
                HTTPResponse feedResponse = http.send(feedRequest);
            }
        }         
        catch(Exception ex)
        {
            System.debug('exception in BatchCurrecnyCovnersionUpdate.execute method '+ex.getMessage());
        }

 
nagendra kumar 21nagendra kumar 21
Hi Raj, i actually dont understand how to use it,
can you help me setp by setp. 
can you contact me to my email if that is okay nagendra.snowfall@gmail.com
Shruthi MN 28Shruthi MN 28
raj can u help me with the enitire code of updating multicurency