0

So I had a business requirement of creating a certain type of field (I called it Account Link) that is basically a link to an account name or id. This was quite simple and this is how I created it:

HYPERLINK('/' +
IF(NOT(ISBLANK(Parent.Parent.Parent.Parent.Parent.Name)), Parent.Parent.Parent.Parent.Parent.Id,
IF(NOT(ISBLANK(Parent.Parent.Parent.Parent.Name)), Parent.Parent.Parent.Parent.Id,
IF(NOT(ISBLANK(Parent.Parent.Parent.Name)), Parent.Parent.Parent.Id,
IF(NOT(ISBLANK(Parent.Parent.Name)), Parent.Parent.Id,
IF(NOT(ISBLANK(Parent.Name)),Parent.Id,
Id))))),
IF(NOT(ISBLANK(Parent.Parent.Parent.Parent.Parent.Name)), Parent.Parent.Parent.Parent.Parent.Name,
IF(NOT(ISBLANK(Parent.Parent.Parent.Parent.Name)), Parent.Parent.Parent.Parent.Name,
IF(NOT(ISBLANK(Parent.Parent.Parent.Name)), Parent.Parent.Parent.Name,
IF(NOT(ISBLANK(Parent.Parent.Name)), Parent.Parent.Name,
IF(NOT(ISBLANK(Parent.Name)),Parent.Name,
Name))))))

The problem is that business now wants to use the 18 digit id instead of 15 and thats where I am stumped. I know salesforce allows to use the CASESAFEID() method but that would be a formula field within a field . In other words, i tried replacing wherever i have Id with CASESAFE(ID) but it doesnt work. I also made a separate field that converts the 15 digit id to 18 and then referenced that field name (account_18_id, I called it) and replaced that with wherever I have id in the formula field. But that does not work either because in both cases I get the errir:

Error: Compiled formula is too big to execute (14,809 characters). Maximum size is 5,000 characters

Can someone please help me resolve this issue?

1

You can shrink your formula dramatically by replacing IF(NOT(ISBLANK(X, X, IF(NOT(ISBLANK, Y, etc)) with BLANKVALUE(X, BLANKVALUE(Y, etc)). Once you've done so, that should free up enough characters to wrap the first BLANKVALUE call in CASESAFEID. You can also save some characters by using Parent.Id instead of ParentId for all your terminal field paths.

HYPERLINK('/' + CASESAFEID(
    BLANKVALUE(Parent.Parent.Parent.Parent.ParentId,
        BLANKVALUE(Parent.Parent.Parent.ParentId,
            BLANKVALUE(Parent.Parent.ParentId,
                BLANKVALUE(Parent.ParentId, ParentId)
            )
        )
    )),
    BLANKVALUE(Parent.Parent.Parent.Parent.Parent.Name,
        BLANKVALUE(Parent.Parent.Parent.Parent.Name,
            BLANKVALUE(Parent.Parent.Parent.Name,
                BLANKVALUE(Parent.Parent.Name, Parent.Name)
            )
        )
    )
)
1
  • Unfortunately, it doesn't work. I tested this in my org, and it compiles to 10,284 characters. CASESAFEID uses a minimum of 2,000 compiled characters by itself.
    – sfdcfox
    Jun 29 at 15:04
1

CASESAFEID is simply too expensive to use in this formula. I wasn't able to get your code to smaller than 10,000 characters, which was optimized as:

HYPERLINK(
    '/'+
    CASESAFEID(
        BLANKVALUE(
            Parent.Parent.Parent.Parent.ParentId,
            BLANKVALUE(
                Parent.Parent.Parent.ParentId,
                BLANKVALUE(
                    Parent.Parent.ParentId,
                    BLANKVALUE(
                        Parent.ParentId,
                        BLANKVALUE(
                            ParentId, 
                            Id
                        )
                    )
                )
            )
        )
    ),
    BLANKVALUE(
        Parent.Parent.Parent.Parent.Parent.Name,
        BLANKVALUE(
            Parent.Parent.Parent.Parent.Name,
            BLANKVALUE(
                Parent.Parent.Parent.Name,
                BLANKVALUE(
                    Parent.Parent.Name,
                    BLANKVALUE(
                        Parent.Name,
                        Name
                    )
                )
            )
        )
    )
)

You'll want to create a URL field, then use a Workflow Field Update, Process Builder, or a Before Save Flow, and update the URL field with the formula. Unlike these formulas, the Automation Field Updates don't have a compile size limit that I'm aware of, since the value is only used for calculation.

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.