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
Rachel Linder 20Rachel Linder 20 

compile error of 'Error: Compiled formula is to big to execute (6,428 characters). Maximum size is 5,000 characters).'

I have this formula field I am trying to build. Here is the current formula that is throwing the compilation error above:
 
IF( 
   ISPICKVAL(Opportunity.StageName,"Closed Lost"),0,
     IF( 
        AND(Opportunity_Record_Type__c = 'Amendment',
           OR(Line_Level_Detail__c <> 'New Logo',
              Line_Level_Detail__c <> 'Cross Sell',
              Line_Level_Detail__c <> 'Upgrade / Downgrade',
              Line_Level_Detail__c  <> 'Services',
              Line_Level_Detail__c  <> 'Product Churn',
              Line_Level_Detail__c  <> 'Product Deprecated',
              Line_Level_Detail__c  <> 'Customer Credit')), TotalPrice,
            IF(
               AND(Opportunity_Record_Type__c  <>  'Amendment',  Line_Level_Type__c  <> 'Removed Product', 
                 OR(Line_Level_Detail__c <> 'New Logo',
                    Line_Level_Detail__c <> 'Cross Sell',
                    Line_Level_Detail__c <> 'Upgrade / Downgrade',
                    Line_Level_Detail__c  <> 'Services',
                    Line_Level_Detail__c  <> 'Product Churn',
                    Line_Level_Detail__c  <> 'Product Deprecated',
                    Line_Level_Detail__c  <> 'Customer Credit')), TotalPrice,
                IF(
                   AND(Opportunity_Record_Type__c  <>  'Amendment',  Line_Level_Type__c = 'Removed Product',
                     OR(Line_Level_Detail__c = 'Upgrade / Downgrade',
                        Line_Level_Detail__c = 'Migration',
                        Line_Level_Detail__c = 'Bundle Adj')), Combined_Renewed_Subscription_Total_Amt__c ,        

           0)
)
)
)

I know that the compilation error is due to things such as formulas on formulas, etc. But is there anything I can do to re-write it.
AbhishekAbhishek (Salesforce Developers) 
Hi,

The compiles size for a given formula includes the compile sizes for other formulas that it has referenced. The additive nature of compile size is causing you to exceed the limit with this one.

Without seeing the content in your other formulas, it's hard to say exactly what's causing the large compile size. Before you leap to Apex, it's worth a look to see if your formulas are written as efficiently as possible (which is a good practice anyway). There is a doc from Salesforce on this very topic, Tips for Reducing Formula Size (http://resources.docs.salesforce.com/226/12/en-us/sfdc/pdf/salesforce_formula_size_tipsheet.pdf), which has a number of suggestions and examples:

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 (or trigger)
Your biggest win will be reducing formulas that are referenced multiple times.

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
 
Vinodraj ShivanandaVinodraj Shivananda
As per https://help.salesforce.com/articleView?id=formula_field_limits.htm&type=5 a formula can contain upto 3900 characters. Workaround is to go with workflow field update which bypasses the character limit.
AbhishekAbhishek (Salesforce Developers) 
Please check 

Character limit—Formula fields can contain up to 3,900 characters, including spaces, return characters, and comments. If your formula needs more characters, create separate formula fields and reference them in another formula field.

NOTE The maximum number of displayed characters after an evaluation of a formula expression is 1,300.

You have to follow the suggestions which I have suggested.
Rachel Linder 20Rachel Linder 20
question - with a workflow rule will it go back and update the field on items created prior to the WFR being created?
Alain CabonAlain Cabon
Is the field Line_Level_Detail__c a formula field?

This block is duplicated and you should test is first

IF( Line_Level_Detail__c <> 'New Logo',
Line_Level_Detail__c <> 'Cross Sell',
Line_Level_Detail__c <> 'Upgrade / Downgrade',
Line_Level_Detail__c <> 'Services',
Line_Level_Detail__c <> 'Product Churn',
Line_Level_Detail__c <> 'Product Deprecated',
Line_Level_Detail__c <> 'Customer Credit')

That is not a working formula below but the idea is to prevent the re-test of the same block above by testing it first.
IF(ISPICKVAL(Opportunity.StageName,"Closed Lost"),0,

IF( Line_Level_Detail__c <> 'New Logo', 
Line_Level_Detail__c <> 'Cross Sell', 
Line_Level_Detail__c <> 'Upgrade / Downgrade', 
Line_Level_Detail__c <> 'Services', 
Line_Level_Detail__c <> 'Product Churn', 
Line_Level_Detail__c <> 'Product Deprecated', 
Line_Level_Detail__c <> 'Customer Credit')

       ... AND(Opportunity_Record_Type__c = 'Amendment',
         
       ... AND(Opportunity_Record_Type__c  <>  'Amendment',  Line_Level_Type__c  <> 'Removed Product', 

 IF( AND(Opportunity_Record_Type__c <> 'Amendment', 
         Line_Level_Type__c = 'Removed Product', 
      OR(Line_Level_Detail__c = 'Upgrade / Downgrade', 
         Line_Level_Detail__c = 'Migration', Line_Level_Detail__c = 'Bundle Adj')),               Combined_Renewed_Subscription_Total_Amt__c ,