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
Jose ZunigaJose Zuniga 

replacing last_month


I have some code that depends on LAST_MONTH. Something like:

select .... date__c .. FROM myTable__c where date__c = LAST_MONTH

This code, as I understand, returns a result set constrained to

firstOfPastMonth <= date__c <= LastOfPastMonth

In order to make this query ready to run for any other month and not only for the last one, I tried to eliminate the use of LAST_MONTH by using variables like:

iniMonth = myToday.addMonths(-1).toStartOfMonth(); endMonth = iniMonth.addDays(date.daysInMonth((integer) iniMonth.year(), (integer) iniMonth.month()));

where myToday represents a call to a date that belongs to the month just after the needed month. So I got:

select .... date__c ... FROM myTable__c where date__c >= iniMonth AND date__c < endMonth

Am I missing something? Please, let me know Thanks
Best Answer chosen by Jose Zuniga
NagendraNagendra (Salesforce Developers) 
Hi Jose,

May I suggest you please check with similar post on stack exchange community with similar issue and suggested workaround.

http://salesforce.stackexchange.com/questions/160163/replacing-last-month

Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Best Regards,
Nagendra.

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Jose,

May I suggest you please check with similar post on stack exchange community with similar issue and suggested workaround.

http://salesforce.stackexchange.com/questions/160163/replacing-last-month

Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Best Regards,
Nagendra.
This was selected as the best answer
Jose ZunigaJose Zuniga
I am the one who posted the same question at stackexchange. Sometimes, I get very good alternatives not considered at StackExchange and viceversa.