Loading

Use Images in Salesforce Formula Fields

Publiseringsdato: Mar 1, 2025
Beskrivelse

These instructions outline the process of creating a formula custom field to display a specific image determined by the value of another field within an object.

For example, use a custom formula field to highlight the status of an Opportunity, Lead, Case Age, or the dollar amount in a Contract.
 

Løsning

 Create a custom formula field to display an image


Note:

The formula fields used in a compact layout render as long as the image is uploaded on Files. Otherwise, it shows a broken image in the field.

You can't display an image related to a contact in a custom formula field if it's referenced through a Person account.

 In Lightning Experience

  1. Create a public library to hold your image files if one is not already created. For steps, see Manage Libraries from Files Home.

  2. Upload your image files to your library. For steps, see Add Files to a Library.

  3. Create a custom field within the Object where you want the images to display. For steps, see Create Custom Fields.

    • Main Field Type - Formula

    • Name your custom field, then select Text from the "Formula Return Type" picklist/button.

    • In the "Enter Formula" screen, click Advanced Formula.

  4. Obtain the URL to the image files uploaded in Step 2:

    1. Go back to Files.

    2. Select the library created in Step 1.

    3. Select an image to view the image preview.

    4. Right-click the image, then select Copy image address. Save this image URL so you don't lose it. Example URLs:

      • "/sfc/servlet.shepherd/version/renditionDownload?rendition=ORIGINAL_Jpg&versionId=06846000002mPro&operationContext=CHATTER&contentId=05T46000009hQHt/image.jpg"

      • "/sfc/servlet.shepherd/version/download/06846000002mPro"

  5. In your new custom field, enter the image URL into your formula field using the "IMAGE" function.

    1. In the text area, enter your formula using the "IMAGE" function to retrieve the image file you uploaded in Step 2. To ensure the image displays fully on reports, enter the height and width as shown in Example 2 below.

    2. Paste the image URL into the "image_url" section of the IMAGE function. Notes:

      • Don't include the Salesforce domain ("https://www.salesforce.com") in your URL.

      • URLs must be enclosed in double-quotes, for example, "/sfc/servlet.shepherd/version/download/0687000000dz7Ex"

  6. Repeat Step 4 and Step 5 until each image URL is added to your new custom field. When complete, click Next.

  7. Grant the appropriate Field-Level Security to your new custom field, then click Next.

  8. Add your new custom field to all relevant page layouts, then click Save.


 

In Salesforce Classic

  1. Create a public folder to hold your image files.

    1. Click the Documents tab.

    2. Click Create New Folder.

    3. Enter the folder name (For example, "Public Images").

    4. Give Users "Read-Only" access to the folder and make it accessible to all Users.

  2. Upload your image file to your Documents storage area.

    1. Click the Documents tab.

    2. Click New.

    3. Enter the document name to be displayed on the browser.

    4. From the "Folder" picklist, select the folder you created in Step 1.

    5. Click Browse to locate and select the file to upload.

    6. Click Save.

  3. Create a custom field within the Object where you want the images to display. For steps, see Create Custom Fields.

    • Main Field Type - Formula

    • Name your custom field, then select Text from the "Formula Return Type" picklist/button.

      In the "Enter Formula" screen, click Advanced Formula.

  4. Obtain the URL to the image files uploaded in Step 2:

    1. Click the Documents tab.

    2. From the "Folder" picklist, select the folder you created in Step 1.

    3. Click Go.

    4. Click View next to the name of the file you want to use. A new browser window or browser tab opens.

    5. In the browser's address bar, select and copy the URL.

  5. In your new custom field, enter the image URL into your formula field using the "IMAGE" function.

    1. In the text area, enter your formula using the "IMAGE" function to retrieve the image file you uploaded in Step 2. To ensure the image displays fully on reports, enter the height and width as shown in Example 2 below.

    2. Paste the image URL into the "image_url" section of the IMAGE function. Notes:

      • Don't include the Salesforce domain ("https://www.salesforce.com") in your URL.

      • URLs must be enclosed in double-quotes, for example, "/sfc/servlet.shepherd/version/download/0687000000dz7Ex"

  6. Repeat Step 4 and Step 5 until each image URL are added to your new custom field. When complete, click Next.

  7. Grant the appropriate Field-Level Security to your new custom field, then click Next.

  8. Add your new custom field to all relevant page layouts, then click Save.



Example Formula Fields

Example 1

This example displays a GIF image of a green square if the amount of an Opportunity is greater than 100, a yellow square if it's under 51 and 99, and a red square if it's less or equal to 50.
 

IF( Amount > 100, IMAGE("/servlet/servlet.FileDownload?file=01570000000Q6El", "Green"),
IF ( Amount > 50, IMAGE("/servlet/servlet.FileDownload?file=01570000000Q6Ef", "Yellow"),
IMAGE("/servlet/servlet.FileDownload?file=01570000000Q6Ep", "Red")))

 

IMPORTANT: Although percentage fields appear to have whole number values, they are decimals. For example, 50% in the opportunity probability field is entered as 0.5, not 50. So the formula for a percent field should look like this (using probability field as example):
 

IF ( Probability > 0.50, IMAGE("/servlet/servlet.FileDownload?file=01570000000Q6Ef", "Yellow")

 

Example 2 

This example displays an external JPG image of a flower regardless of the value in any field (replace the image url with the full path of your image):

IMAGE("http://images.odeo.com/1/8/4/Zencast.jpg", "Flower", 300, 300)


For more information on the IMAGE formula and to understand the parameters, please review this Online Help.
 

Knowledge-artikkelnummer

000385501

 
Laster
Salesforce Help | Article