• Shruthi MN 28
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Can anyone help me to get a code to auto update exchange rates using curreny layer api 
For Example If Opportunity curreny is CAD then it will convert automatically to USA
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
I have written a trigger wherein I want all the opportunity amount to roll up on quote Actual_amount__c feild. The conditions are the opportunity should be closed won and and the opptunity should be on this month(jan). I am jnot able to get the logic right. Can anyone help me with the same

trigger LookupRollup on Opportunity (before insert) {
List<id> ParentIds = new List<id>();
    
    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){
        For(Opportunity Opp : Trigger.new){
            ParentIds.add(Opp.Amount);
        }
    }
    if(Trigger.isDelete){
        For(Opportunity Opp : Trigger.old){
            ParentIds.add(Opp.Amount);
        }
    }
    List<Quota__c> ProductsToUpdate = new List<Quota__c>();
    decimal sum = 0;
    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate || trigger.isdelete){
        For(Quota__c q : [SELECT Name ,(SELECT id FROM  Actual_Amount__c) FROM Quota__c WHERE id =: ParentIds]){
            sum = 0;
            for(Opportunity p : q.Amount){
                
                sum = sum + 1;
            }
            q.Actual_Amount__c = sum;
            
        }
        ProductsToUpdate.add(q);        
    }
    try{
        update ProductsToUpdate;
    }Catch(Exception e){
        System.debug('Exception :'+e.getMessage());
    }
}
 
I have written a trigger wherein I want all the opportunity amount to roll up on quote Actual_amount__c feild. The conditions are the opportunity should be closed won and and the opptunity should be on this month(jan). I am jnot able to get the logic right. Can anyone help me with the same

trigger LookupRollup on Opportunity (before insert) {
List<id> ParentIds = new List<id>();
    
    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){
        For(Opportunity Opp : Trigger.new){
            ParentIds.add(Opp.Amount);
        }
    }
    if(Trigger.isDelete){
        For(Opportunity Opp : Trigger.old){
            ParentIds.add(Opp.Amount);
        }
    }
    List<Quota__c> ProductsToUpdate = new List<Quota__c>();
    decimal sum = 0;
    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate || trigger.isdelete){
        For(Quota__c q : [SELECT Name ,(SELECT id FROM  Actual_Amount__c) FROM Quota__c WHERE id =: ParentIds]){
            sum = 0;
            for(Opportunity p : q.Amount){
                
                sum = sum + 1;
            }
            q.Actual_Amount__c = sum;
            
        }
        ProductsToUpdate.add(q);        
    }
    try{
        update ProductsToUpdate;
    }Catch(Exception e){
        System.debug('Exception :'+e.getMessage());
    }
}
 
Hi All, 
please help me developing code or share code who to write apex class for this scenario and how to schedule it.

req - 
1) Fetch the exchange rate (CAN/USD) from some publicly available api using apex
2) Given this exchange rate create a Currency Conversion Record with the correct start date, end date and exchange rate.
3) Run a scheduled job to run (1) and (2) once per month.

thanks 
nagendra