7

What is the right way to get the converted currency in SOQL?

I've got this in my query:

      SELECT Owner.UserRole.Name, Id, Name, Include_in_Forecast__c, convertCurrency(Amount) FROM Opportunity

HERE's the sample output in my VF page:

VF Page sample output

I only used 1 List<Opportunity> here and a variable for Total

Looks like I've got the original currency record from the Opportunity.

Thanks in advance!

UPDATE : My expected total is the sum of EUR(current user's currency) and it's 7939.47

2
  • So you want to Sum AUD, NZD, and EUR(So you were expecting a total of 18,494.47)?
    – EricSSH
    Commented Jul 9, 2014 at 16:45
  • the current user's currency and it's the EUR, so the TOTAL must be 3951.50 + 3987.97 = 7939.47.Sorry if the sample image confused you.
    – mdechavez
    Commented Jul 9, 2014 at 16:49

2 Answers 2

2

:D So I came up with this solution.

I created a wrapper class:

public class OppDispWrapper {
    private Decimal pvtAmount = 0.00;
    public Decimal amount  { get{return pvtAmount;} set{pvtAmount = value;} }
    public Opportunity oppTbl {get; set;}
}

This is how I assigned values:

List<Opportunity> oppList = [SELECT Owner.UserRole.Name, Id, Name, Include_in_Forecast__c, convertCurrency(Amount)/*Amount*/, StageName, isWon, isClosed, OwnerId, CloseDate, ForecastCategoryName 
                                 FROM Opportunity 
                                 WHERE OwnerId in: userSet 
                                 AND Record_Type__c = :'Licence Fee'
                                 AND CALENDAR_MONTH(CloseDate) = : month 
                                 AND CALENDAR_Year(CloseDate)  = : year];

    totalOppInForecast = 0;
    countOppInForecast = 0;
    for (Opportunity o : oppList){
        OppDispWrapper odw = new OppDispWrapper();
        odw.oppTbl = o;
        odw.amount = o.Amount;
        if (oppCategory == 'pipeLine'){
            if (!o.isClosed){
                oppDispWrapList.add(odw);
                if(o.Include_in_Forecast__c){
                    totalOppInForecast = totalOppInForecast + odw.amount;
                    countOppInForecast = countOppInForecast + 1;
                }
            } 
        }
        if (oppCategory == 'closed'){
            if (o.isWon){
                oppDispWrapList.add(odw);
                if(o.Include_in_Forecast__c){
                    totalOppInForecast = totalOppInForecast + odw.amount;
                    countOppInForecast = countOppInForecast + 1;
                }
            } 
        }
        if (oppCategory == 'cdmCamForecast'){
            if (o.ForecastCategoryName == 'CDM/CAM Forecast'){
                oppDispWrapList.add(odw);
                if(o.Include_in_Forecast__c){
                    totalOppInForecast = totalOppInForecast + odw.amount;
                    countOppInForecast = countOppInForecast + 1;
                }
            } 
        }
        if (oppCategory == 'allIncludedInForecast'){
            if (o.Include_in_Forecast__c){
                oppDispWrapList.add(odw);
                totalOppInForecast = totalOppInForecast + odw.amount;
                countOppInForecast = countOppInForecast + 1;
            }
        }
    }

Don't mind about the conditions like oppcategory and other ifs. You can make your own condition. The important code is these:

OppDispWrapper odw = new OppDispWrapper();
odw.oppTbl = o;
odw.amount = o.Amount;

...

oppDispWrapList.add(odw);

...

totalOppInForecast = totalOppInForecast + odw.amount;

Here's a peek on my VF page:

enter image description here

The amount and total displayed is the current user's currency.

Here's the code on my VF page:

<apex:pageBlockSection columns="1">              
                <apex:pageBlockTable id="pbtOpp" value="{!oppDispWrapList}" var="odw" columns="7" rendered="{!showOppTbl}">
                    <apex:column headerValue="Opportunity Name">
                        <apex:outputLink value="/{!odw.oppTbl.id}" target="_blank" >{!odw.oppTbl.Name}</apex:outputLink>
                    </apex:column>
                    <apex:column headerValue="Owner" value="{!odw.oppTbl.OwnerId}"  />
                    <apex:column headerValue="Owner Role" value="{!odw.oppTbl.Owner.UserRole.Name}"  />
                    <apex:column headerValue="Included in Forecast" value="{!odw.oppTbl.Include_in_Forecast__c}"  />
                    <apex:column headerValue="Stagename" value="{!odw.oppTbl.StageName}"  />
                    <apex:column headerValue="Close Date" value="{!odw.oppTbl.CloseDate}"  />
                    <apex:column headerValue="Amount" value="{!odw.amount}"  />
                </apex:pageBlockTable>
            </apex:pageBlockSection>

Hope this helps everybody too!:)

cheers!!!

(ノ≧∀≦)ノヽ(;^o^ヽ)

0

The answer you seek is not entirely as simple as you might think. It depends on how your org handles currency conversion. Please see my answer to Rollup Summary Using Apex Trigger for a further explanation of the relevant issues and links to documentation I think you'll find helpful.

1
  • I'll read the link you've shared. Thanks for your help.
    – mdechavez
    Commented Jul 11, 2014 at 3:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .