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
KyriacosKyriacos 

Would a formula or trigger be better?

I have been working on a formula but I cannot make it without exceeding the compile limit. Shown below if a fraction of the formula. Do you know how I could reduce the compile size? Or do you know if a trigger would be better to use? If so, could you give me an example of how to get that trigger started??

 

IF(
AND( CONTAINS(Domain__c,"DK") , Account_Balance__c < 500),
"Prize Draw",
IF(AND(CONTAINS(Domain__c,"DK"), Account_Balance__c < 2000,Account_Balance__c > 499 ),
"25",
IF(AND(CONTAINS(Domain__c,"DK"), Account_Balance__c < 5000,Account_Balance__c > 1999 ),
"50",
IF(AND(Domain__c = "COM BR", Account_Balance__c < 3000,Account_Balance__c > 599 ),
"Prize Draw",
IF(AND(Domain__c = "COM BR", Account_Balance__c < 15000,Account_Balance__c > 2999 ),
"15",
"No Prize")))))

 

 

 

 

elmaschingondeguateelmaschingondeguate

Try using CASE instead of IF, also, considering splitting the formula in different fields. Another option is to do the operation on a field update rather than a formula field.

V1nitV1nit

Implement this using a Workflow rule with field updates under that. This is would be much easier to do so.

KyriacosKyriacos

Using the workflow rule I would have to use multiple field updates, but I cannot guarantee the order the field updates occur. Therefore if it does not meet the criteria of the final field update it will go to "No Prize", however it may have already met the criteria of one of the other field updates and then be overwritten with "No Prize".

 

I have also considered using CASE but I do not think it would work for this case. The outcome depends on the value of more than one field.

V1nitV1nit

IF(
Domain__c = "DK",
IF(Account_Balance__c < 500,"Prize Draw",
IF(AND(Account_Balance__c < 2000,Account_Balance__c >499),25,
IF(AND(Account_Balance__c < 5000,Account_Balance__c >1999),50,""))),
IF(Domain__c = "COM BR",IF(AND(Account_Balance__c < 3000,Account_Balance__c >599),"Prize Draw",
IF(AND(Account_Balance__c <1500, Account_Balance__c >2999),"No Prize","")),""))

 

 

Can you try the above formula.

I haven't tested it. Let me know the outcome.

 

Cheers.

Vinit.