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
Shruthi MN 28Shruthi MN 28 

Autoupdate currency in my org

I need to auto update currecny based on the exchange rates. For example if the exchange rate os curren 1 dollar = 76.14INR and tomorrow it changes to 76.89 INR so I need to capure the rates automatically in my org. I have wrotten the apex code. Can you corect the logic of my code and correct the error


    public static  void exchangerate (List<Opportunity> newOptyList) {
        
        List<Id> oppOwnerIds = new List<Id>();
        for(Opportunity opp: newOptyList)
        {
            if(opp.OwnerId != null)
            {  
                oppOwnerIds.add(opp.OwnerId); 
            }
        }
        
        Map<Id, User> userList = new Map<Id, User>([SELECT Id, Name, CurrencyIsoCode FROM User WHERE Id IN :oppOwnerIds]);
        
        for(Opportunity opp: newOptyList)
        {
            if(opp.name != '')
            {
                opp.currencyisocode=userList.get(opp.OwnerId).currencyisocode;
            }
        }
    }

}

User-added image

I am getting above error
AbhishekAbhishek (Salesforce Developers) 
Hi,

Don't think there is a direct way to automate this update.

However, the following idea link has some interesting workaround which you might want to check using data loader scheduler:

https://success.salesforce.com/ideaView?id=08730000000BqZr

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.