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
Meenakshi T RMeenakshi T R 

Update date ofpreviously created record.

I have a class on object project. It has two fields start date and end date. So when the start date and end date are entered then a new subproject (It is also the same project object) with the same start date and end date gets created. 
Now the logic in the class runs something like this
1. When the end date of the project(parent) is changed to next year then a new subproject needs to be created- This is working as expected.
2.The problem with this logic is when end date of the project is changed to a same year then also subproject is getting created taking the end date of the previous project as the start date and given a new end date.

So my query is it possible to change the end date of the first subproject according to our scenarios
1. When the new end date is in next year then the end date of the first subproject should become the last day of the year.
2. When the end date is in the same year then no creation of a new subproject just update the existing subproject's end date.

It is invoked by after update after insert trigger
ShirishaShirisha (Salesforce Developers) 
Hi Meenakshi,

Greetings!

You would need to write the logic based on the End Date field value by querying and using the if condition.

Sample formula for the Last day of the year is as below:
 
DATE(YEAR(Start_Date__c), 12, 31)
Reference:https://trailblazers.salesforce.com/answers?id=9063A000000e4DaQAI

Please mark it as best answer if it helps you to fix the issue.

Thank you!

Regards,
Shirisha pathuri
Meenakshi T RMeenakshi T R
Hi Sirisha,

Thank you for the suggestion. We do have it in place. The only method I'm looking for
is how to update the first child subproject with the last date of the year if the entered end date is in next year.