0

I was trying to enter the below formula into a new formula field to track Contract End Dates when compared to a picklist and date field, while incorporating leap years. But I hit a compile Limit, I am a solo admin and have very minimal developing skills. Thank you for your input!

DATE ( 
/*YEAR*/ 
YEAR( Customer_Installation_Completed_Date__c ) + FLOOR((MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c - 1)/12), 

/*MONTH*/
 CASE(MOD(MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c, 12 ), 0, 12, MOD(MONTH(Customer_Installation_Completed_Date__c)+ Contract_Term_Months__c, 12 )), 

/*DAY*/
 MIN(DAY(Customer_Installation_Completed_Date__c), CASE(MOD(MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c,12), 9, 30, 4, 30, 6, 30, 11, 30, 2, 

/* return max days for February dependent on if end date is leap year */ IF(MOD(YEAR(Customer_Installation_Completed_Date__c) + FLOOR((MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c)/12), 400) = 0 || (MOD(YEAR(Customer_Installation_Completed_Date__c) + FLOOR((MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c)/12), 4) = 0 && MOD(YEAR(Customer_Installation_Completed_Date__c) + FLOOR((MONTH(Customer_Installation_Completed_Date__c) + Contract_Term_Months__c)/12), 100) <> 0 ), 29,28), 31)) )

Customer_Installation_Completed_Date__c is a date field and Contract_Term_Months__c is a formula field with the following formula

CASE( 
Contract_Term__c, 
"12 months", 12, 
"24 months", 24, 
"36 months", 36, 
"60 months", 60, 
"N/A", null, 
null)
6
  • Not a proper answer but check out similar case: salesforce.stackexchange.com/a/85939/22513
    – kazoolsky
    Commented Aug 11, 2015 at 13:44
  • Are Customer_Installation_Completed_Date__c and Contract_Term_Months__c also formula fields? If so then adding the code from them will help people figure out a solution for you.
    – BarCotter
    Commented Aug 11, 2015 at 14:02
  • Customer_Installation_Completed_Date__c is a date field Contract_Term_Months__c is a formula field- CASE( Contract_Term__c, "12 months", 12, "24 months", 24, "36 months", 36, "60 months", 60, "N/A", null, null)
    – JazzyJ
    Commented Aug 11, 2015 at 14:07
  • Salesforces formula builder isn't very smart so every time Contract_Term_Months__c is referenced in your formula it replaces that field name with the formula for that field. That is why you can hit the limit for seemingly small formulas
    – BarCotter
    Commented Aug 11, 2015 at 15:07
  • Can you add details as to what your formula does? Does it add the contract term months on to a date? If so then maybe something like this would meet your needs? Customer_Installation_Completed_Date__c + ((Contract_Term_Months__c / 12) * 365)
    – BarCotter
    Commented Aug 11, 2015 at 15:16

2 Answers 2

3

The query that’s compiled from your formula syntax is limited by the maximum query size that the database can execute. This limit is the same for all Salesforce editions: Maximum formula size (in bytes) when compiled: 5,000 bytes.

Fortunately there are ways to work around this limit, and you can avoid it in many cases by making your formulas more efficient.

  • Minimize the number of references to other fields
  • Minimize the number of times formula functions are called
  • Rethink your picklist
  • Think about the problem another way
  • If all else fails, use a workflow field update

I believe you can move this into Workflow field Update (quick and easy way). For Your Information there is a limit on total number of bytes used for Formula fields (32,000 bytes total size per object).

0

What you need to do in these cases is to create a workflow rule with a field update. The formula field is much larger so you will not create a compile error (for size)

The workflow rule should be as simple as you can make it but ensure that you have a check to make sure the date in question is not blank

You must log in to answer this question.

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