ShowAll Questionssorted byDate Posted

# Anyway to optimize this workflow formula?

Hello All,

I currently have a working workflow formula as follows:

IF(Product2.Name = "13-Credits" && Quantity = 1, 13,
IF(Product2.Name = "13-Credits" && Quantity = 2, 13 * 2,
IF(Product2.Name = "13-Credits" && Quantity = 3, 13 * 3,

)))

I know I can either keep this formula as is or use a Case function. However, if I need to 100 different Quantity values, this will require me to have 100 different lines on the formula for each Quantity value. Even worst if I have 10 different Product2.Name requiring 100 different Quantity variations, the number of lines in this formula can easily = 10 * 100 = 1000 lines!

Is there any way I can reduce the number of lines in the this formula?

Please respond with specific working formula examples.

Thanks,

Kiran Kurella

Try this:

IF(Product2.Name = "13-Credits", 13, 0) * Quantity

You should consider moving the rates to a custom object and use Apex to handle the logic for several products.

Kiran Kurella

Try this:

IF(Product2.Name = "13-Credits", 13, 0) * Quantity

You should consider moving the rates to a custom object and use Apex to handle the logic for several products.

This was selected as the best answer
Shannon Hale

If Product2.Name always starts with the number of credits followed by a hyphen, you could potentially simplify this further:

`VALUE( LEFT( Product2.Name, FIND( "-", Product2.Name ) - 1 ) ) * Quantity`

This strips out the digits from the beginning of the name and turns them into a number, and then multiplies that number by the quantity to get the total number of credits. So the same line works for any product as long as the name follows the format "N-xxx".

You would probably also want to write a validation rule on Product2 to ensure that the product names are entered in the correct format; you could do that like this:

`NOT( ISNUMBER( LEFT( Product2.Name, FIND( "-", Product2.Name ) - 1 ) ) )`