IMAGE() Function in Salesforce [Use Cases, Syntax & Examples]

While working as a Salesforce admin, recently, I got a client requirement to automatically display the company logo on the account record as soon as a new account is created or an updated account name.

The client did not want users to upload logos manually. Instead, they wanted Salesforce to show the correct logo based on the Account Name.

To meet this requirement, I created a Formula field using the IMAGE() function. This formula checks the account name and displays the matching logo from a static resource where we used to store images.

In this tutorial, we will learn how to use the IMAGE() Function in Salesforce. We will also learn the syntax and real-world business examples of when we can use the function.

What is the Salesforce IMAGE() Function?

The Salesforce IMAGE() function is one of the functions used to display an image in object fields. This Salesforce IMAGE() Function is used to insert an image with alternate text and height and width specifications.

In addition, the following is the syntax of the Salesforce IMAGE function:

IMAGE(image_url, alternate_text, height, width)

Here is a detailed description of the parameters:

  • image_url: The image_url parameter specifies the path of the image that you want to insert.
  • alternate_text: The alternate_text parameter specifies the text to display when the image can’t be displayed or rendered due to technical or network issues. The screen reader software uses this alternate text.
  • height: The height parameter specifies the vertical size of the inserted image. It always takes the size of an inserted image in pixels.
  • width: The width parameter specifies the width, or you can say the horizontal size of the image that you want to set for the inserted image. The image width can always be specified in pixels.

In addition, there are some considerations that we must remember while using the IMAGE function:

  1. Optional Parameters: In Salesforce, the image function accepts four parameters: image_url, alternate_text, height, and width. Of these four parameters, height and width are optional; you can leave them blank if you want.
  2. Limitation: You cannot display the image for contacts in Salesforce custom fields when the image is referenced via a person’s account.
  3. Text Type Parameters: Always remember that in Salesforce, the IMAGE function’s image_url and alternate_text parameters are of type text. Make sure to enclose both parameter values in the quotes.
  4. Availability: You can only use this IMAGE function in formula fields and email templates.
  5. Number Type Parameter: The height and width parameter of the IMAGE function takes values only as numbers without any quotation marks.
  6. GETSESSIONID Function: In the IMAGE function, you cannot use the Salesforce GETSESSIONID function as an argument.
  7. Store Images: You can store the image in the Salesforce Documents and use the URL of the document in the image_url parameter of the IMAGE function as the reference to the image.
  8. Internet Explorer Settings: If you are using Internet Explorer to display images via the HTTP protocol, you need to adjust the security settings in Explorer; otherwise, you will see a warning prompt.

Additionally, keep in mind that the IMAGE Function returns the result in the form of text, so select the formula return type as TEXT. If you choose any other field type as the return type of the formula field, you will get an error.

Now, we will learn how to add an image to the formula field using the IMAGE() function in Salesforce.

Use the Image() Function in Salesforce

The following steps show how to use the Salesforce IMAGE Function to add an image to a formula field in Salesforce.

  1. Open Salesforce Lightning mode. Next, click the “Gear Icon” in the top right corner of the page. Click Setup from the dropdown menu to continue.
IMAGE Function in Salesforce
  1. The setup page opens when you select the Setup option. Here, the “Object Manager” is found in the Navigation Bar next to the Home tab. Click on it.
IMAGE Function in Salesforce Example
  1. The object manager page opens when you click it. There are numerous objects seen here. Use the Quick Find search field to locate the item we want to use the Image() function on.
    • Now, click the “Product” object to move to the lead object page.
IMAGE Function in Salesforce Lightning
  1. On the product object page, the “Field & Relationship” option is in the details section on the left. Select “Field & Relationship” from the menu.
    • The field and relationships page is opened after selecting the field and relationship option. Click the “New” button at the top of the page.
IMAGE Function in Salesforce Lightning Example
  1. The field type page opens when you click the new button. The page contains a wide variety of field types. In this case, I chose the “Formula” field type, as I want to use the Image function in the advanced formula.
    • Click the “Next” button to move on to the next step.
Salesforce IMAGE Function
  1. Now, it’s time to set up the field label and formula return type. So, firstly, I entered the “Field Label” as “Product Image” and when I click on the “Field Name“, it gets automatically filled up.
    • Once I scrolled down, I saw an option to choose the formula return type from the available field types. But as you know, the Salesforce IMAGE function only returns the result in the text format and gives an error if you choose any other field type. So, I select “Text” by clicking on the radio button next to it.
    • After that, click on the “Next” button and proceed to the next step.
Salesforce IMAGE Function Example
  1. In this step, enter the formula you need in the advanced formula bar using the function. For this, first move to the right side of the page, towards the”Functions” section, and click on the dropdown labeled “All Functions Categories”.
    • From the dropdown, choose “Text,” as the IMAGE function is part of Salesforce’s Text Categories. On clicking on the text, you will get all the Salesforce functions that are under the text category. Now, search for the “IMAGE” function, select it, and click the “Insert Selected Function” button.

Once the function is entered in the advanced formula box, replace its parameters with the fields, links, or values needed, as required. Let’s see an example to understand it.

Suppose I want to add a product image so it’s easier for the customer and seller to identify. The formula for this scenario is as given below:

IMAGE("https://tech_it_iphone11.png", "IPhone11 Product Iamge", 10, 6)

Here, we use the IMAGE function of Salesforce to insert an image with these parameters:

  • image_url: Here, we pass the URL “https://tech_it_iphone11.png”, which points to the image we want to represent.
  • alternate_text: Here, we set the text to “iPhone 11 Product Image,” which displays when the image cannot be displayed.
  • height: Here we pass the height parameter and set the image’s height to 10 pixels.
  • width: Here we pass the width parameter and set the image’s width to 6 pixels.
  1. Now, click on the “Check Syntax” button to verify that the formula has no errors. If there is no error, you will see the message “No syntax errors in merge fields or function”. But if there is an error, you will see an error notification on the screen.
    • If you would like, you can define the “Description” and “Help Text,” as well as “Handle the empty field.” Then click the “Next” button to proceed to the next step.
IMAGE() Function in Salesforce
  1. In this step, establish Field-Level Security. Choose the profiles to which we wish to grant field-level security edit access to this field. If field-level security is not added, the field will be hidden from all profiles.
    • As I want it to be visible to all profiles, I have checked the “Visible” checkbox. After that, click the “Next” button located at the top.
Salesforce Lightning IMAGE Function Example
  1. Add the custom field to the Page Layout after setting up the field-level security. Pick the page layout that has this field in it. If we do not select a layout, the field will not appear on any pages.
    • To save the formula field, click the “Save” button.
How to add image in the formula field in Salesforce Lightning

Once the formula field is created, you can use the formula field. Let’s see an example:

  • Open the Product item, create a new product, and save the products.
  • After saving it, move to the Products Details section and here you will get the Product Image field that shows the result of the IMAGE function.
How to add image in the formula field in Salesforce Lightning Example

With this, we have learned how to add an image in the formula field using the IMAGE function in Salesforce.

Conclusion

In this way, we have learned the Salesforce IMAGE function, including its syntax and various real-world business examples. We have also learned that the Salesforce IMAGE function is used to insert images in Salesforce.

Moreover, we have learned the step-by-step process for using the IMAGE function in Salesforce to add an image to a Salesforce formula field.

You may like to read the following articles:

live webinar

Data Cloud in Agentforce Data Library

In this live webinar, we will showcase how Salesforce AI Agents use business data and documents to provide intelligent responses using Agentforce Data Library and Salesforce Data Cloud.

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.