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
MystwalkerMystwalker 

automatic update field for money currency conversion

I've seen a few posts concerning this subject, but is there an alternate way to fetch a conversion rate for money on an web site and save it in a variable to use it in reports?

 

I'm really interested to know if someone knows a good or better method to this or something really close,

 

thanks.

Manoj1822Manoj1822
Create a Connected App
Create an Auth. Providers
Create a Named credentials.
Step by Step instruction is given in the below two URLs.
http://www.jitendrazaa.com/blog/salesforce/salesforce-to-salesforce-integration-using-named-credentials-in-just-5-lines-of-code/
https://www.jitendrazaa.com/blog/salesforce/login-to-salesforce-from-salesforce-using-authentication-provider/#more-4516

Once the above configuration is done, please use the below piece of code to update the Managed Dated Currency.

 
        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());
        }