1

I have the following formula:

OR
(
    AND
    (
        Route_to_Legal__c = TRUE,
        OR
        (
            INCLUDES(Agreement_Type__c, "Fulfillment/Supplier"),
            INCLUDES(Agreement_Type__c, "Promotion"),
            INCLUDES(Agreement_Type__c, "Purchase - Equipment"),
            INCLUDES(Agreement_Type__c, "Purchase - Tech (HW)"),
            INCLUDES(Agreement_Type__c, "Services - Non-Tech"),
            INCLUDES(Agreement_Type__c, "Venue/Event"),
            INCLUDES(Agreement_Type__c, "Customer"),
            INCLUDES(Agreement_Type__c, "Licensing/Revenue Share/Royalties"),
            INCLUDES(Agreement_Type__c, "NDA [Non-Standard]"),
            INCLUDES(Agreement_Type__c, "Other"),
            INCLUDES(Agreement_Type__c, "Purchase - Real Estate"),
            INCLUDES(Agreement_Type__c, "Purchase - Tech (SW/SaaS)"),
            INCLUDES(Agreement_Type__c, "Outsourced Manufacturing Partner"),
            INCLUDES(Agreement_Type__c, "Raw Material/Freight"),
            AND
            (
                TEXT(Transaction_Type__c) = "No cost",
                INCLUDES(Agreement_Type__c, "Services - Tech (Labor)")
            )
        )
    ),
    AND
    (
        TEXT(Counter_Party_Access_to_PII__c) = "Yes",
        OR
        (
            INCLUDES(Agreement_Type__c, "Fulfillment/Supplier"),
            INCLUDES(Agreement_Type__c, "Promotion"),
            INCLUDES(Agreement_Type__c, "Purchase - Equipment"),
            INCLUDES(Agreement_Type__c, "Purchase - Tech (HW)"),
            INCLUDES(Agreement_Type__c, "Services - Non-Tech"),
            INCLUDES(Agreement_Type__c, "Venue/Event"),
            INCLUDES(Agreement_Type__c, "Customer"),
            INCLUDES(Agreement_Type__c, "Licensing/Revenue Share/Royalties"),
            INCLUDES(Agreement_Type__c, "NDA [Non-Standard]"),
            INCLUDES(Agreement_Type__c, "Other"),
            INCLUDES(Agreement_Type__c, "Purchase - Real Estate"),
            INCLUDES(Agreement_Type__c, "Purchase - Tech (SW/SaaS)"),
            INCLUDES(Agreement_Type__c, "Outsourced Manufacturing Partner"),
            INCLUDES(Agreement_Type__c, "Raw Material/Freight"),
            AND
            (
                TEXT(Transaction_Type__c) = "No cost",
                INCLUDES(Agreement_Type__c, "Services - Tech (Labor)")
            )
        )
    ),
    AND
    (
        Agreement_Value__c >= 25000.00,
        OR
        (
            INCLUDES(Agreement_Type__c, "Fulfillment/Supplier"),
            INCLUDES(Agreement_Type__c, "Promotion"),
            INCLUDES(Agreement_Type__c, "Purchase - Equipment"),
            INCLUDES(Agreement_Type__c, "Purchase - Tech (HW)"),
            INCLUDES(Agreement_Type__c, "Services - Non-Tech"),
            INCLUDES(Agreement_Type__c, "Venue/Event"),
            INCLUDES(Agreement_Type__c, "Customer"),
            INCLUDES(Agreement_Type__c, "Licensing/Revenue Share/Royalties"),
            INCLUDES(Agreement_Type__c, "NDA [Non-Standard]"),
            INCLUDES(Agreement_Type__c, "Other"),
            INCLUDES(Agreement_Type__c, "Purchase - Real Estate"),
            INCLUDES(Agreement_Type__c, "Purchase - Tech (SW/SaaS)"),
            INCLUDES(Agreement_Type__c, "Outsourced Manufacturing Partner"),
            INCLUDES(Agreement_Type__c, "Raw Material/Freight"),
            AND
            (
                TEXT(Transaction_Type__c) = "No cost",
                INCLUDES(Agreement_Type__c, "Services - Tech (Labor)")
            )
        )
    ),
    AND
    (
        Agreement_Value__c < 25000.00,
        OR
        (
            INCLUDES(Agreement_Type__c, "Licensing/Revenue Share/Royalties"),
            INCLUDES(Agreement_Type__c, "Purchase - Real Estate"),
            INCLUDES(Agreement_Type__c, "NDA [Non-Standard]"),
            INCLUDES(Agreement_Type__c, "Other"),
            INCLUDES(Agreement_Type__c, "Customer"),
            AND
            (
                TEXT(Transaction_Type__c) = "No cost",
                INCLUDES(Agreement_Type__c, "Services - Tech (Labor)")
            )
        )
    ),
    AND
    (
        Multi_Year_Contract__c > 12.0,
        TEXT(Has_Exit_Clause__c) = "No",
        OR
        (
            INCLUDES(Agreement_Type__c, "Fulfillment/Supplier"),
            INCLUDES(Agreement_Type__c, "Promotion"),
            INCLUDES(Agreement_Type__c, "Purchase - Equipment"),
            INCLUDES(Agreement_Type__c, "Purchase - Tech (HW)"),
            INCLUDES(Agreement_Type__c, "Services - Non-Tech"),
            INCLUDES(Agreement_Type__c, "Venue/Event"),
            INCLUDES(Agreement_Type__c, "Customer"),
            INCLUDES(Agreement_Type__c, "Licensing/Revenue Share/Royalties"),
            INCLUDES(Agreement_Type__c, "NDA [Non-Standard]"),
            INCLUDES(Agreement_Type__c, "Other"),
            INCLUDES(Agreement_Type__c, "Purchase - Real Estate"),
            INCLUDES(Agreement_Type__c, "Purchase - Tech (SW/SaaS)"),
            INCLUDES(Agreement_Type__c, "Outsourced Manufacturing Partner"),
            INCLUDES(Agreement_Type__c, "Raw Material/Freight"),
            AND
            (
                TEXT(Transaction_Type__c) = "No cost",
                INCLUDES(Agreement_Type__c, "Services - Tech (Labor)")
            )
        )
    )
)

It exceeds the maximum character limit of 3,900 characters. Is there a better way to write this formula to reduce the characters to get under the 3,900 limit?

2
  • Each of your inner OR statements seem to be repeated multiple times and seems to be a condition of every single branch. Can you consolidate those in one place? – nbrown Apr 7 at 20:41
  • A start could be to try to group the includes, so you don't have to repeat them so often. – Sergio Alcocer Apr 7 at 20:46
6

Using symbols to represent your conditions (or group of conditions) makes it easier to simplify boolean expressions. Having some education in formal logic and/or boolean algebra really helps out here.

Let x replace all of the following:

OR
        (
            INCLUDES(Agreement_Type__c, "Fulfillment/Supplier"),
            INCLUDES(Agreement_Type__c, "Promotion"),
            INCLUDES(Agreement_Type__c, "Purchase - Equipment"),
            INCLUDES(Agreement_Type__c, "Purchase - Tech (HW)"),
            INCLUDES(Agreement_Type__c, "Services - Non-Tech"),
            INCLUDES(Agreement_Type__c, "Venue/Event"),
            INCLUDES(Agreement_Type__c, "Customer"),
            INCLUDES(Agreement_Type__c, "Licensing/Revenue Share/Royalties"),
            INCLUDES(Agreement_Type__c, "NDA [Non-Standard]"),
            INCLUDES(Agreement_Type__c, "Other"),
            INCLUDES(Agreement_Type__c, "Purchase - Real Estate"),
            INCLUDES(Agreement_Type__c, "Purchase - Tech (SW/SaaS)"),
            INCLUDES(Agreement_Type__c, "Outsourced Manufacturing Partner"),
            INCLUDES(Agreement_Type__c, "Raw Material/Freight"),
            AND
            (
                TEXT(Transaction_Type__c) = "No cost",
                INCLUDES(Agreement_Type__c, "Services - Tech (Labor)")
            )
        )

There's one iteration of that which is shorter

OR
        (
            INCLUDES(Agreement_Type__c, "Licensing/Revenue Share/Royalties"),
            INCLUDES(Agreement_Type__c, "Purchase - Real Estate"),
            INCLUDES(Agreement_Type__c, "NDA [Non-Standard]"),
            INCLUDES(Agreement_Type__c, "Other"),
            INCLUDES(Agreement_Type__c, "Customer"),
            AND
            (
                TEXT(Transaction_Type__c) = "No cost",
                INCLUDES(Agreement_Type__c, "Services - Tech (Labor)")
            )
        )

let that be represented as y

The other parts are short enough, but for example's sake let's assign each one to a different letter, a-f.

That shortens our representation to this:

OR(
    AND(a, x),
    AND(b, x),
    AND(c, x),
    AND(d, y),
    AND(e, f, x)
)

In more standard boolean expression format
(a && x) || (b && x) || (c && x) || (d && y) || (e && f && x)

That (d && y) kinda messes us up a little bit. If that were (d && x) instead, we could simply take x out of each sub-expression using the distributive property of logical and/or
(i.e. (a && x) || (b && x) === x && (a || b))

Not all hope is lost though. y is a subset of x (if y is true, then x must also be true), but I think the easier way to go about this would be to re-arrange and group things to make it easier for us to factor out the common elements.

Think of it like re-arranging a mathematical formula 2x + 4xy + 3y as 2x(1 + 2y) + 3y.

First, group things to help make it clear what we can factor out
( (a && x) || (b && x) || (c && x) || (e && f && x) ) || (d && y)

Then we can pull x out of the left sub-expression
( x && (a || b || c || (e && f)) ) || (d && y)

Now that should be precisely equivalent to the original statement, but it is possible I've made a mistake somewhere. Assuming I haven't, we can then turn that into the typical Salesforce formula format

OR(
    AND(
        x,
        OR(
            a,
            b,
            c,
            AND(e, f)
        )
    ),
    AND(d, y)
)

I'll leave the work of fully re-expanding that (replacing a-f and x and y with their actual conditions) to you.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.