+ Start a Discussion
cambart14cambart14 

Fiscal Quarter from Close Date (Custom Fiscal Years Enabled)

I am trying to figure out how to translate a list of Close Dates in the respective Fiscal Quarters.  We have custom fiscal years enabled in the org.

The code below is completely functional, except line 13.  How do convert the Close Dates to Fiscal Quarters.

Thanks!
 
public string getData()
  {    List<PivotData> PivotDataList=new List<PivotData>();
   List<OpportunityLineItem> OppList=[Select Opportunity.Account.Name,Opportunity.StageName,Opportunity.CloseDate,
   Opportunity.Amount,Opportunity.RecordTypeID,CurrencyISOCode,Expected_Total_Price__c,Opportunity.IsClosed, Quantity,
   Opportunity.Name,PriceBookEntry.Product2.Name,Opportunity.Probability,PriceBookEntry.Product2.Description from OpportunityLineItem 
   WHERE Opportunity.OwnerID =: UserInfo.getUserId() AND Opportunity.IsClosed = FALSE ];
       for(OpportunityLineItem o :OppList)
       {
           PivotData p=new PivotData();
           p.AccountName=o.Opportunity.Account.Name;
           p.StageName=o.Opportunity.StageName;
           p.Year=string.valueof(o.Opportunity.CloseDate.Year());
           p.Quarter=string.valueof(o.Opportunity.CloseDate.FiscalQuarter());
           p.CurrencyCode=o.Opportunity.CurrencyISOCode;
           p.ExpectedTotalPrice=o.Expected_Total_Price__c;
           p.OpportunityName=o.Opportunity.Name;
           p.ItemNumber=o.PriceBookEntry.Product2.Name;
           p.Probability=o.Opportunity.Probability;
           p.ItemDescription=o.PriceBookEntry.Product2.Description;
           p.Quantity=o.Quantity;
           
           PivotDataList.add(p);
           
       }
       getPivot='visibility: visible';
       exportPdf=false;
       return JSON.serialize(PivotDataList);
  }

 
NagaNaga (Salesforce Developers) 
Hi Cambart,

User-added image
Please see the link below

https://success.salesforce.com/answers?id=90630000000hnMzAAI

Best Regards
Naga Kiran
cambart14cambart14
@Naga,

Thank you for the suggestion, but this code is part of an interactive javascript pivot table that goes beyond the capabilities of the standard matrix report.  I have everything working except with this interactive pivot table, except for how I can translate the close date into the respective fiscal quarters.
Victor CazacuVictor Cazacu
Here is how i solved it:

if (o.ScheduleDate.month()<4){p.ScheduledRevenueQuarter='Q1';}
        else if (o.ScheduleDate.month()<7){p.ScheduledRevenueQuarter='Q2';}
        else if (o.ScheduleDate.month()<10){p.ScheduledRevenueQuarter='Q3';}
        else  {p.ScheduledRevenueQuarter='Q4';}
cambart14cambart14
@Victor

Thank you for your suggestion. It appears your solution takes in consideration the calendar months and quarters.  We have fiscal quarters that do not align with the end of calendar month and this solution would not be able to break the date into fiscal quarters.