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

Apex Month Name


I have an insert in an object A (with two dates). After the insertion of the object A, an insertion of an object B will be done in such a way that:
- The number of records inserted is equal to the number of months between the two dates.
- The field Name of the object B is equal Month name + Year.

Can someone help me.
Sunil SirangiSunil Sirangi
@AichaSF: Please follow the below steps in your apex code.

1) Validate whether both dates are present and in case of any future validations.
2) Use "monthsBetween" method provided by salesforce to find the number of months.
3) now use a for loop to insert the number of records. 

Let me know if this helps. Happy to provide code snippet if you stuck somewhere in the process.