I need to write a logic to update a field with a date from next month. For example, today's date is 28/10/2020 11:00:00 AM, the field should be updated with 28/11/2020 11:00:00 AM. So just the value of month needs to be changed and also it needs to be handled when the year changes.
Kindly suggest what can be done in apex for this. The current logic that I have made is for adding 1 day.
DateTime dT1 = DateTime.Now().AddDays(1);
String newDate = dT1.format('yyyy-MM-dd');
String nextrun = newDate + ' ' + obj.Hour__c + ':' + obj.Minute__c+ ':'+'00';
Datetime dt = DateTime.valueOf(nextrun);
if(obj.Hour__c!='*' && !(obj.Hour__c.contains(',')))
{
obj.Next_Run__c= dt;
update obj;
}
Thanks, Surabhi Panwar