1

I have a class that is looking for contracts 30 days before the end Date.

My problem is i am trying to build a test for this class, and in that i'm trying to create a contract where the End Date is 30 days ahead of today's date. No matter what i set the contract Term as, the endDate is always getting set as a year from today, rather than from the contract StartDate and the Term.

Does anyone have any suggestions here?

    contract con = new contract();

    con.StartDate =system.today().addMonths(-11);
    con.ContractTerm=12;
    insert con;
    con.Status = 'Activated';
    update con;
    system.debug(con.StartDate+'<-----------Start  End----------->'+ con.EndDate);

Debug line: 14:22:41:910 USER_DEBUG [64]|DEBUG|2017-12-13 00:00:00<-----------Start End----------->2019-11-12 00:00:00

2
  • Have you checked if you have any process builder / workflow / 3rd party apps that may be setting the End Date? Nov 15, 2018 at 5:54
  • @DavidCheng - I found a contract setting "Auto-calculate Contract End Date". I switched this off an i was able to set the End Date manually for my test Nov 16, 2018 at 11:05

1 Answer 1

1

In Setup, there's a Auto-calculate Contract End Date setting under Contract Settings. If enabled, the End Date will be set automatically based on the Start Date and Term.

Since you report that the End Date is always one year from the Start Date, regardless of the Term that you set, there is perhaps a trigger or flow changing the Term. You can add an assertion in your test to verify that Start Date and Term are being stored with the values you set.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .