Updating multi currency rates from Apex

The Metadata API does not give access to this information, this is used for org configuration such as custom objects and fields. CurrencyType and DatedConversionRate contain record level information. As per the documentation you linked to, you can use the SOAP API to insert and udpate records in these.

All standard and custom objects can also be accessed through the SOAP API.

Which I also assume would mean the REST API aswell and indeed it does...

Here is a working REST API insert via Apex for DatedConversionRate...

    Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v28.0/sobjects/DatedConversionRate/');
    req.setBody('{ "IsoCode" : "ADP", "ConversionRate" : 1.5, "StartDate" : "2013-06-26" }');
    req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
    req.setHeader('Content-Type', 'application/json');
    req.setMethod('POST');
    HttpResponse res = h.send(req);

Here is a working REST API update via Apex for DatedConversionRate...

    Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v28.0/sobjects/DatedConversionRate/04wb0000000KzHlAAK?_HttpMethod=PATCH');
    req.setBody('{ "ConversionRate" : 2.5 }');
    req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
    req.setHeader('Content-Type', 'application/json');
    req.setMethod('POST');
    HttpResponse res = h.send(req);

Note: Using setMethod('PATCH') gives an Apex error. The documentation for HttpRequest.setMethod does not list 'PATCH' as a method, though it says 'for example', so its unclear if its saying its not supported or the documentation author just missed it out.

Fortunately you can override the Http method as a URL parameter as described here.

If you use an HTTP library that doesn't allow overriding or setting an arbitrary HTTP method name, you can send a POST request and provide an override to the HTTP method via the query string parameter _HttpMethod. In the PATCH example, you can replace the PostMethod line with one that doesn't use override: PostMethod m = new PostMethod(url + "?_HttpMethod=PATCH");


Although this is a few years old it is still awesome and saved my bacon. Part of our solution needed to remove some Dated Conversion Rate records as well. Thought I'd just throw this up here for quick reference even though everyone could probably figure it out pretty quickly.

Here is a working REST API delete via Apex for DatedConversionRate...

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v28.0/sobjects/DatedConversionRate/04wb0000000KzHlAAK?_HttpMethod=DELETE');
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
req.setHeader('Content-Type', 'application/json');
req.setMethod('POST');
HttpResponse res = h.send(req);