2
votes

is there a work around towards calculating the accurate contract end date for a closed deal in Salesforce? We have a field which calculates the contract end date based on the [ Revenue_Date__c + ( Contract_Length__c * 30) ] , however, this is based on the assumption all months have 30 days, is there a work around this to get a more accurate contract end date?
We are on a Professional edition of Salesforce.

1

1 Answers

0
votes

As far as I know it will be very tricky to do it with functions/formulas. You could start experimenting with this thing that finds the end of current month:

DATE(
    YEAR(TODAY()),
    MONTH(TODAY()),
    CASE( MONTH(TODAY()),
        1, 31,
        2, IF( MOD( YEAR(TODAY()), 4) = 0, 29, 28),
        3, 31,
        4, 30,
        5, 31,
        6, 30,
        7, 31,
        8, 31,
        9, 30,
        10, 31,
        11, 30,
        12, 31,
        DAY(TODAY())
    )
)

You could try calculating the difference between days and the end of this year, next year etc (depending on the contract length) but it will be a very nasty solution. And I cry a little every time I see home-grown date handling "library"...

Can you move the logic to apex? In a simple "before insert, before update" trigger it'd be very easy:

for(My_Object__c o : trigger.new){
    o.Contract_End_Date__c = o.Contract_Start_Date__c.addMonths(o.Contract_Length__c);
}

In "before" trigger you get save to DB for free as a bonus ;) So essentially same as users would see it if it's a formula field.