In our multi-currency org, we get daily updates of conversion rates in the DatedConversionRate object and these need to be copied to the CurrencyType object.
For those of you who don't know: DML is not allowed on CurrencyType, you can only update that object via REST API. So a simple Apex trigger will not do, we ended up creating an Apex batch job that performs one REST API call per currency (we have 11 of them).
However, performing those REST API calls one after the other, often results in the error message "rsf calculation in progress" (ALREADY_IN_PROCESS). It seems that changing the rate of a CurrencyType triggers recalculations in Salesforce. You cannot postpone it or influence it in any way.
As I see it, there are two solutions:
- Allow more time between the REST API calls.
- Offer all updates in one composite REST API call.
The second solution seems the cleanest. However, I cannot get it to work. For those of you new to composite REST API calls, the URL that you use ends in /composite
and the body contains the actual updates. Each update must have an element called referenceId.
So I did this and the body looks like this:
{
"compositeRequest": [
{
"url": "https://ourcompanysandbox.sandbox.my.salesforce.com/services/data/v52.0/sobjects/CurrencyType/01L58000000Lz7iEAC?_HttpMethod=PATCH",
"referenceId": "AUD",
"method": "POST",
"body": {
"ConversionRate": 1.4687
}
},
...
But unfortunately, it doesn't work. The REST API call for the composite returns HTTP code 200, but for each of the updates, the body reports an HTTP 400 code, with the error 'https://ourcompanysandbox.sandbox.my.salesforce.com/services/data/v52.0/sobjects/CurrencyType/01L58000000Lz7iEAC?_HttpMethod=PATCH' is not a valid url
(PROCESSING_HALTED)
This is the exact same URL as we used for the individual updates, but all of a sudden it is not valid anymore? I don't understand.
UPDATE: After I had implemented the composite REST API call successfully, it turned out that the updates inside the composite call are not executed in a single transaction, as I had hoped. The call still fails, because of the "rsf calculation in progress" issue. So the real solution is to implement retries or spread the individual calls out in time.
.sandbox
in the url. Could this be an issue with enhanced domain enabled in the org?/services
onwards, hence probably reporting the HTTP 400 error.