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
IT Admin DeloitteIT Admin Deloitte 

Trigger vs Class

Hi All,

I've got the following problem:

In Opportunity there is a trigger that updates the standard field Currency in the object Pipeline_c, that is USD by default.
The trigger works, in fact, saving the Opportunity, I can see that the Pipeline's Currency actually changes, from USD to GBP (for example).
Now, I have a Class that uses the Pipeline's Currency and calculates some values if Currency is different than USD.
When a press 'Save' in the Class, nothing happen, because the 'Save' turns the Pipeline's Currency in USD again!.

Why?
In my class I never update the Pipeline's Currency to USD again. It is only its initial value that it should be update in GBP by the trigger.

Thankyou
Ezdhan Hussain S KEzdhan Hussain S K
HI, 
Can you give more details on your question. 
what i understood is trigger changes USD to GBP.
And class changes GBP to USD.

share more info or code snippet.
IT Admin DeloitteIT Admin Deloitte
Whaty you say is the final results. The problem is that the class is not supose to change the currency back in USD. It should just use the new currency.

I'ts like the class write again USD, but it should'nt. Here's the trigger. 
 
trigger UpdateCurrency on Opportunity (after insert, after update) {

public List<Pipeline_Item__c> PLI{get;set;}
public Pipeline__c ppl {get;set;}

public List<Pipeline__c> planning {get;set;}


for(Opportunity opp: Trigger.new){

PLI= [SELECT CurrencyIsoCode FROM Pipeline_Item__c WHERE Pipeline__r.Opportunity__r.Id=: opp.Id ];
          if(PLI.size() >0){
            for (Pipeline_Item__c  pl : PLI){
               pl.CurrencyIsoCode = opp.CurrencyIsoCode ;
               update pl;
            }
          }
planning = [SELECT CurrencyIsoCode FROM Pipeline__c WHERE Opportunity__r.Id =:opp.Id];
              if(planning.size() >0){
                Pipeline__c pip = planning.get(0);
                pip.CurrencyIsoCode = opp.CurrencyIsoCode;
                update pip;
              }
          }    
}
And here's the Class Save method:
public PageReference save() {

    
        update ppl ;    

        Boolean fyok = true;
        Set<Decimal> fypresent = new Set<Decimal>();
 
        for (Pipeline_Item__c pl: ppl.Pipeline_Items__r)
        {
            if (pl.Fiscal_Year__c!= null && pl.Fiscal_Year__c!= 0)
            {
 
                if (fypresent.contains(pl.Fiscal_Year__c)){
                  fyok = false;
                }
                fypresent.add(pl.Fiscal_Year__c);
          }
 
        }
 
        if (fyok){

            for (Pipeline_Item__c pl: ppl.Pipeline_Items__r)
            {
                update pl;
            }
      }
     
        reload();

      update ppl ;

      fyok = true;
       fypresent = new Set<Decimal>();
 
        for (Pipeline_Item__c pl: ppl.Pipeline_Items__r)
        {
            if (pl.Fiscal_Year__c!= null && pl.Fiscal_Year__c!= 0)
            {
 
                if (fypresent.contains(pl.Fiscal_Year__c)){
                  fyok = false;
                }
                fypresent.add(pl.Fiscal_Year__c);
          }
 
        }
 
        if (fyok){
            for (Pipeline_Item__c pl: ppl.Pipeline_Items__r)
            {
                update pl;
            }
      }

      
       updateActualsMor();
        return null;
      
        reload();
        return null;


    }