 ShowAll Questionssorted byDate Posted Lavanya

# How to give formula field dynamically in Visual force using PE in salesforce

Hi All,

when I save the below formula, it shows this error:

Error: Compiled formula is too big to execute (19,959 characters). Maximum size is 5,000 character

if the sum of Value_1__c to Value_13__c <= 10, then  display level 1

if the sum of Value_1__c to Value_13__c >10 and Value_1__c to Value_13__c <= 18, then  display level 2

if the sum of Value_1__c to Value_13__c >18 then level 3

formula value:

if((Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c) <= 10

&&
(Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c ) <> 0 , "Level 1",
if( AND((Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c + Value_10__c + Value_11__c + Value_12__c + Value_13__c) > 10
&&
(Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c) <= 18), "Level 2",
if((Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c) > 18,"Level 3",
"Level Not Calculated Yet" )))

All field Value_1__c to Value_13__c also formula field which get s the value from the picklist selected.

we tried this also:

total_risk_cal__c = Value_1__c + Value_2__c +Value_3__c + Value_4__c + Value_5__c + Value_6__c + Value_7__c + Value_8__c + Value_9__c+ Value_10__c + Value_11__c + Value_12__c + Value_13__c

if((total_risk_cal__c) <= 10
&&
(total_risk_cal__c ) <> 0 , "Level 1",
if( AND((total_risk_cal__c) > 10
&&
(total_risk_cal__c) <= 18), "Level 2",
if((total_risk_cal__c) > 18,"Level 3",
"Level Not Calculated Yet" )))

but getting same error. We are trying an alternate method of creating a whole page using VF. We didn't get any ideal for how to give fomula field dynmaically in Visual force we are using professional edition. Kindly any one tell how to dao this and please send me any sample code for this also some links. Thanks in advance, waiting for you reply.

Regards,

Lavanya. Best Answer chosen by Admin (Salesforce Developers)  Karthikeyan Jayabal
Ok, change all those 13 fields' formula to use CASE function like:

CASE( X1__c , 'New Client / Contact to Palaris', 1, 'Existing client / contact to Palaris', 2, 'Work completed previously by Palaris',3,'New type of work to Palaris',4,0)

Hopefully, this should reduce the complied size to half. Try & let me know. Karthikeyan Jayabal
I think the error is NOT due to the number of characters in your formula expression, but it's not able to calculate 13 fields. The best way is to create a child object with the value field, then calculate the sum using a roll-up summary field at the parent object. Lavanya

Thanks for the reply.   Can you pls tell  me more about this, i am using this opportunity object only.  It is possible using VF page dynamic formula field. If so pls tell how to create this dynamic formula field. asish1989

HI

The error is due to number of character used in that formula field because Formula fields can contain up to 3900 characters, including spaces and line breaks.

http://wiki.developerforce.com/page/An_Introduction_to_Formulas

If this post answers your questions please mark it as solved and give kudos for this post If it helps you

Thanks Karthikeyan Jayabal

I'm not sure what kind of business information is captured in your Value 1-13 fields. But, as they're all the same numeric values, it's best to not create individual redundant fields. Below are the detailed steps:

1. Create a new custom object & relate it to the Opportunity object via a Master-detail relationship field.

2. Create your Value field at the new custom object

3. Create a roll-up summary field at Opportunity object, which calculates the SUM

4. Then finally, add another formula field to Opportunity object based on the total field created at step 3 to calculate the Level.

Hope this helps. Karthikeyan Jayabal
I have even tried it your way & it works fine for me.
Added 13 Value fields to Opportunity object (Type: Number(18,0)).
Below are the formula fields:

1. Total_Value__c = Value_1__c+Value_2__c+Value_3__c+Value_4__c+Value_5__c+Value_6__c+Value_7__c+Value_8__c+Value_9__c+Value_10__c+Value_11__c+Value_12__c+Value_13__c
Formula(Number) : Compiled size: 452 characters

2. Value_Level__c = IF(Total_Value__c<=10&&Total_Value__c<>0, 'Level 1',IF(Total_Value__c>10&&Total_Value__c<=18, 'Level 2',IF(Total_Value__c>18,'Level 3','None')))
Formula(Text) : Compiled size: 2,452 characters Lavanya

hi Karthikayen, thanks for the reply. Value_1__c  to value_2__c are the formula fields. Is it possible for this formula field Karthikeyan Jayabal
Oh.. I thought they're just number fields. So, can you share the exact formula of those fields? I know they're derived from a pick list.
Also, you can explain the business process at a high level. What are these 13 fields & so on...? Lavanya

These 13  fileds  values  from the formula fields based on another picklist value .

Eg: sample picklist1 has red, blue, green . All the picklist fields has a unique value "Red = 2", green =3" "blue=4". If  we select Red then the value 2 is passed to Value_1__c likewise for the all the field get the value.

Value_1__c = if ( ISPICKVAL( X1__c , "New Client / Contact to Palaris" ) ,1,if( ISPICKVAL( X1__c , "Existing client / contact to Palaris "),2,if( ISPICKVAL( X1__c ,"Work completed previously by Palaris"),3,if(ISPICKVAL( X1__c ,"New type of work to Palaris"),4,0))) ) Karthikeyan Jayabal
Ok, change all those 13 fields' formula to use CASE function like:

CASE( X1__c , 'New Client / Contact to Palaris', 1, 'Existing client / contact to Palaris', 2, 'Work completed previously by Palaris',3,'New type of work to Palaris',4,0)

Hopefully, this should reduce the complied size to half. Try & let me know.
This was selected as the best answer Lavanya

Hi Karthikeyan, Thanks a lot for the reply. I am trying this