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
Jos Vervoorn 2Jos Vervoorn 2 

Sum within loop

I try to get a table populated with .. target versus actuals per year/month based on quota and line item schedule revenue value

I have created to Lists. One of Quotas (Sales targets) and another on Opportunity Line Item schedule.and I'working with a nested loop (forgive me the inefficiency) ....
For (OpportunityLineItemSchedule OppS:LineItemSchedList){
      For (ForecastingQuota FQ:MyForeCastquotaList){

        If ((FQ.StartDate.Year() == OppS.ScheduleDate.Year()) && (FQ.StartDate.Month() == OppS.ScheduleDate.month()){
           LineCounter = LineCounter  + 1;

           System.debug(LoggingLevel.Info,'[******] --------------------------------------------------');
           System.debug(LoggingLevel.Info,'[******] Month          ..: '+FQ.StartDate.Month());
           System.debug(LoggingLevel.Info,'[******] FQ.Currency    ..: '+FQ.currencyisocode);
           System.debug(LoggingLevel.Info,'[******] FQ.QuotaAmount ..: '+FQ.QuotaAmount);
           System.debug(LoggingLevel.Info,'[******] FQ.Owner       ..: '+FQ.quotaOwner.Name);
           System.debug(LoggingLevel.Info,'[******] Item Revenue   ..: '+OppS.Revenue);
           System.debug(LoggingLevel.Info,'[******] LineCounter    ..: '+LineCounter);           
        }
      }
   }

So ultimately want to have a sum on OppS.Revenue per month/year ..... but for some reason I'm not getting this to work. Now you may wander why i'm not using aggregate list ... well ... it's simple ... convertCurrency(QuotaAmount) is not allowed on aggregate and on a multi currency I need to make sure all quota's and actuals are in singular (read EUR) currency.

Once I have this I will insert the rows (target/actuals) in a table so I can simply report on this and schedule a job to (auto) populate and refresh the table ... 

Any help / direction is much appreciated ....

 
Alain CabonAlain Cabon

 "I need to make sure all quota's and actuals are in singular (read EUR) currency."

If a query includes a GROUP BY or HAVING clause, currency data returned by using an aggregate function, such as SUM() or MAX(), is in the org’s default currency.

https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_querying_currency_fields.htm

If your org’s default currency is EUR, all the aggregations are in EURO.

Mutlicurrency also means (Dated) Conversion Rate and you can convert the results into any other currency using the object CurrencyType.

You can verify your currencies with this SOQL query: 

SELECT IsoCode, ConversionRate, DecimalPlaces, IsActive, IsCorporate, CreatedDate FROM CurrencyType