ShowAll Questionssorted byDate Posted
grandak koy

# Due date Apex Class

need to be able to calculate the “Due Date” of a record when a certain picklist is chosen.
I have a parent object: Shipment, the child object Orders, and the child object of orders  “packages"
If the parent object “Shipment” has a picklist chosen of “Urgent” or “Shipped”I need to set the  Due date  to Tuesday based off of the created date being on a Monday.
So if the created date is on a Tuesday, then the due date will be Thursday. The due date will be on a PACKAGE object if the package is of type “8x”
If it is of type “5x” the due date will be that following Monday, so if the created date was tues, set due date for that following Monday for packages of “5x”

How can I write an apex class for this? I can’t do it in a formula because I have exceed the character limit.
Hi,
I am not able to fully understand your requirement. Can you please explain using an example?
grandak koy
Hi,

If I my Shipment record = "Urgent" then I would need to set the Due Date for a certain amount of days after the created date of shipment depending on what day of the week the created date of shipment is. For example, if the created date is on a Friday, I want the due date to be the following Tuesday if the package record is of "8x" The problem is that package is not a direct child of shipment, it is a child of Orders. Orders is then the direct child of Shipment. Does that make sense?
grandak koy
I Guess how could I simplify this formula:

IF( Status__c =‘Processing’|| Status__c=‘Demanded'',

IF(
MOD(CreatedDate - DATE(1900, 1, 7), 7) = 0,
CreatedDate
+2,
IF(
MOD(CreatedDate
- DATE(1900, 1, 7), 7) = 1,
CreatedDate
+1,
IF(
MOD(CreatedDate
- DATE(1900, 1, 7), 7) = 2,
CreatedDate
+2,
IF(
MOD(CreatedDate
- DATE(1900, 1, 7), 7) = 3,
CreatedDate
+1,
IF(
MOD(CreatedDate
- DATE(1900, 1, 7), 7) = 4,
CreatedDate
,
IF(
MOD(CreatedDate
- DATE(1900, 1, 7), 7) = 5,
CreatedDate
+4,
IF(
MOD(ICreatedDate
- DATE(1900, 1, 7), 7) = 6,
CreatedDate
+ 3, null))))))),

It repeats 4 more times for other statuses and my compile error exceeds 5k