wanted to get end date for Current Fiscal Quarter in apex any ideas, how to get this information.
Attribution to: Prafulla Patil
Possible Suggestion/Solution #1
//for standard calendar year
Date dt = date.newInstance(1014,12, 17);
Integer currentMnt =dt.month();
Integer currentQ =((currentMnt-1)/3) + 1;
Date endOfQDate = date.newInstance(dt.year(),currentMnt + (4 - (currentMnt - ((currentQ -1)*3))) , 1).addDays(-1);
system.debug(endOfQDate);
Attribution to: user7076
Possible Suggestion/Solution #2
I use the below to determine the start month in a quarter.
Date d = Date.today(); // works for any date
Integer quarterStartMonth = (((Math.ceil((Decimal.valueOf(d.month()) / 12) * 4))*3) - 2).intValue();
Date quarterStart = Date.newInstance(d.year(), quarterStartMonth, 1);
Attribution to: OnyxSoul
Possible Suggestion/Solution #3
Try the following, I just wrote it and tested for our fiscal year, worked ok...
Integer FiscalYearStartMonth = [select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;
Date fiscalYearStartDate;
Integer quarter;
if(system.today().month() >= FiscalYearStartMonth)
{
fiscalYearStartDate = date.newinstance(system.today().year(), FiscalYearStartMonth, 1);
quarter = ((system.today().month() - FiscalYearStartMonth) / 3) + 1;
}
else
{
fiscalYearStartDate = date.newinstance(system.today().year() - 1, FiscalYearStartMonth, 1);
quarter = ((12 + system.today().month() - FiscalYearStartMonth) / 3) + 1;
}
Integer addMonths = quarter * 3;
Date lastDateOfThisQuarter = fiscalYearStartDate;
// this is the last date of the current quarter
lastDateOfThisQuarter = lastDateOfThisQuarter.addMonths(addMonths).addDays(-1);
Attribution to: Boris Bachovski
Possible Suggestion/Solution #4
Here is the simplest way I getting date I believe - We just need to query Period Object record and thats it. I think most of us are not aware of this Object in salesforce.com
Date closeDate = [Select EndDate From Period Where type = 'Quarter' and StartDate = THIS_FISCAL_QUARTER].EndDate;
Attribution to: Prafulla Patil
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4166