2

I have a custom currencyConversion object and i want to insert conversion rates on this object on daily basis using a web service(URL). I am new to salesforce integration. How can I achieve this?

Webservice I have is using :

From Currency, To Currency, Start Date, Conversion Rate, Fiscal Period.
1

You can create a Apex job on daily basis to fetch the exchange rate and store in the currencyConversion object. To get the conversion rates you can use any standard standard service provider like Yahoo currency conversion site.

I had posted almost similar solution in this SFSE link. Hope this will help you to build your own solution.

Update - How to Parse the webservice response

String resp = '{"data":{"base":"USD","date":"20160527","rates":[{"currency":"AUD","rate":1.7572},{"currency":"CAD","rate":1.80343},{"currency":"EUR","rate":1.6372},{"currency":"GBP","rate":1.24301},{"currency":"JPY","rate":1.8272},{"currency":"MXN","rate":2.0},{"currency":"NZD","rate":1.52788}]},"pagination":null,"error":null}';

String mycurrency;
Double  myrate = 0.0;
//resp is a JSON string
JSONParser parser = JSON.createParser(resp);
while (parser.nextToken() != null) {
    if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'currency')) {
        parser.nextToken();
        mycurrency= parser.getText();
    }
    if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'rate')) {
        parser.nextToken();
        myrate= parser.getDoubleValue();
        System.debug('currency = '+ mycurrency+' rate = '+myrate);
    }
}
  • Thanks a lot saroj. This ia very helpful. I don't want to use standard yahoo currency conversion rates rather i have a web service so i guess i just need to change the end point url with mine ? – Ridhi May 26 '16 at 9:27
  • Yes, as I mentioned in my solution you can use any webservice you want. If this helps you, can you please accept it as answer. – Saroj Bera May 26 '16 at 10:05
  • Hi Saroj , I am not able to parse the values with the solution you provided as there are many values of rates for different currencies. I want to insert these rates corresponding to the currency in my sf object. Your solution will insert only one conversion rate. what if i want to insert so many rates corresponding to their currency codes. Could you please help. Do we have to write wrapper classes for this ? – Ridhi Jun 1 '16 at 11:58
  • Can you post the response with multiple values? – Saroj Bera Jun 1 '16 at 12:23
  • this is the web service i got.... {"data":{"base":"USD","date":"20160527","rates":[{"currency":"AUD","rate":1.7572‌​},{"currency":"CAD","rate":1.80343},{"currency":"JPY","rate":1.8272},{"currency":"MXN","rate":2‌​.0},{"currency":"NZD","rate":1.52788}]},"pagination":null,"error":null} From this web service i have to insert records in my object something like this- From Currency,To Currency,Start Date,Conversion Rate,Fiscal Period GBP,USD,5/13/16,1.46850000,May 2016 - P8FY16 EUR,USD,5/13/16,1.11500000,May 2016 - P8FY16 – Ridhi Jun 2 '16 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.