IMAGE() Function in Salesforce

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

While working in a multinational company as a Salesforce Developer. I got a task to add the logo of the company to their account records to make sales teams easily recognize it.

As a solution, I found that Salesforce has a function named “IMAGE” using which we can add images. If you want to learn how I use the Salesforce IMAGE function to add the image with several examples go through the entire article.

What is Salesforce IMAGE Function

Salesforce IMAGE() function is one of the various TEXT functions in Salesforce which is used for performing text operations on Salesforce 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 iamge_url parameter specifies the path of the image that you want to insert.
  • alternate_text: The alternate_text parameter specifies the text that you want to show when the image can’t be shown or rendered due to some technical or internet issues. This alternate text is used by the screen reader software.
  • height: The height parameter specifies the height or you can say the vertical size of the image that you want to set to 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 of the inserted image. The width of the image can always be inserted in the pixels.

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

  1. Optional Parameters: In Salesforce image function takes a total of four parameters such as image_url, alternate_text, height, and width, and out of these four parameters two parameters height and width are totally optional you can leave these blank if you want.
  2. Limitation: You can not display the image for the contacts in Salesforce custom fields when the image is referencing through a person’s account.
  3. Text Type Parameters: Always remember that in Salesforce IMAGE function parameters image_url and alternate_text is of the text type. 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 of the image.
  8. Internet Explorer Settings: If you are using Internet Explorer to display the images using the HTTP protocol, you need to adjust the security settings of the Explorer, otherwise it shows the warnings 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 select any other field type as the return type of the formula field, you will get an error.

Let’s see a small example of the IMAGE() Function to better understand the concept:

As I told in the introduction part, while working in the company I got a task to add the logo of the company to their account records to make sales teams easily recognize it. And for this, I used the Salesforce IMAGE function. So, let’s see its formula:

IMAGE("https://tsinfo_technologies_log.png", "Tsinfo Account Logo")

With this, we have learned what is the Salesforce IMAGE function, its syntax, and one example of the function to get a better understanding.

See also  Salesforce YEAR Function

Now, we will move ahead and learn how we can add the image in the formula field using the Salesforce IMAGE function in Salesforce Lightning and Salesforce Classic.

Read INCLUDES() Function in Salesforce

How to add image in the formula field in Salesforce Lightning

The following are the steps to use the Salesforce IMAGE Function to add an image in the formula field in Salesforce Lightning:

Step 1: Login to the Salesforce account in the Lightning Experience. After login, if you are not in the main home page setup, click on the “Gear” icon located on the right side of the page, and from the dropdown menu click on the “Setup” (Setup for current app) option.

IMAGE Function in Salesforce

Step 2: Once you successfully move to the main home page setup of the lightning experience, click on the “Object Manager” option at the navigation bar.

IMAGE Function in Salesforce Example

On a click, the object manager page gets opened with all the Salesforce custom and standard objects. Now search for the object in the “Quick Find” box in which you want to use the Salesforce IMAGE function. Let’s take an example of the “Product” object so I searched for the product object in the quick find and click on it.

IMAGE Function in Salesforce Lightning

Step 3: After clicking on the product, you will redirect to the product page where you can see all the functionalities related to the product. From the left side, click on the “Field & Relationship” option, and after that click on the “New” button as you want to use the IMAGE function in the formula field so for this, you need to create the field first.

IMAGE Function in Salesforce Lightning Example

Step 4: In this step, you will get all the Salesforce Fields Types, choose one from it as per the requirement. According to our requirement, you need to choose formula one as we are going to create a formula field with the IMAGE function.

For this, I click on the radio button next to the “Formula” field type and then click on the “Next” button to move to the next step.

Salesforce IMAGE Function

Step 5: Now, it’s time to set up the field label and formula return type. So, firstly I entered the “Filed Label” as “Product Image” and when I click on the “Field Name” it gets automatically filled up.

Once I scrolled down I get an option to choose the formula return type from the various given field type. But as you know that 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

Step 6: In this step, you have to enter the formula according to your need in the advanced formula bar with 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 the “Text” as we know that the IMAGE function is part of the text categories function of Salesforce. On the click 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 on the button “Insert Selected Function”.

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

Suppose, I want to add the product image so that it becomes helpful for the customer and seller to easily identify it. 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 an image that we want to represent.
  • alternate_text: Here we pass the text as “IPhone11 Product Image” which works when the image cannot be displayed.
  • height: Here we pass the height parameter and set the height of an image to the value of 10 pixels.
  • width: Here we pass the width parameter and set the width of an image to the value of 6 pixels.
See also  Salesforce SECOND Function

Step 7: Now, click on the “Check Syntax” button to verify that the formula has no error. 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 on the “Next” button to move to the next step.

Salesforce Lightning IMAGE Function

Step 8: Now, it’s time to setup the “Field Level Security”. Here, you have to choose the profile to whom you want to grant the field-level security edit access to this field.

In this example, I check the checkbox next to the “Visible” option and after that, I click on the “Next” button to move to the next step.

Salesforce Lightning IMAGE Function Example

Step 9: After setting up the field-level security, you have to add this field to the page layout. Choose the page layout names to which you want to add this custom field. Then, click on 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 Lightning. Next, we will learn how to add an image in the formula field using the IMAGE function in Salesforce Classic.

Read ISPICKVAL() Function in Salesforce

How to add image in the formula field in Salesforce Classic

The following are the steps to add an image using the IMAGE function in the formula field in Salesforce Classic:

Step 1: Logged in to the Salesforce account in the Salesforce Classic Experience. If you are logged in to the Lightning experience, move to the classic by clicking on the “Profile” and from the dropdown click on the option “Switch to Salesforce Classic”.

IMAGE Function in Salesforce Classic

Step 2: Now, click on the “Setup” option at the top right side of the page.

IMAGE Function in Salesforce Classic Example

Step 3: Scroll down to the “Build” section located on the left side of the page. From the build section, click on the “Customize” dropdown and it will show you all the Salesforce objects on which you want to use the IMAGE function. Let’s take an example of the “Contracts” object this time.

So, click on the “Contracts” dropdown, and from the various option choose the “Fields” option.

Salesforce Classic IMAGE Function

Step 4: After you click on the fields option, the contract field page gets opened. Now scroll down to the “Contracts Custom Fields & Relationship” and click on the “New” button to create a new custom field.

Salesforce Classic IMAGE Function Example

Step 5: Choose the field type as per the need. Here, I select the formula field type by clicking on the radio button next to the “Formula”. After that click on the “Next” button to move to the next step.

How to add image in the formula field in Salesforce Classic

Step 6: In this step, you have to choose the output type and enter the field label and name. Here, I enter the “Field Label” as “Contract Documents” and when I click on the “Field Name” the field gets automatically filled up.

See also  Salesforce ISCLONE Function

Move downwards and set up the formula return type for the field. For this example, I select “Text” as the data type because we know that the IMAGE function returns the output in the text format. If you select any other field type as return type you will get an error.

After that, click on the “Next” button to move to the next step.

How to add image in the formula field in Salesforce Classic Example

Step 7: Once you click on the next step, you will move to the enter formula page. Now, enter the advanced formula in the advance formula box. Let’s see an example:

Here, I entered the formula for inserting the images of the contract documents for the verification and renewal process.

IMAGE("htpps://tech_info_contract_document.jpeg", "Contract Documentation", 12, 4)

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

  • image_url: Here we pass the URL “htpps://tech_info_contract_document.jpeg” which points to an image that we want to insert.
  • alternate_text: Here we pass the text as “Contract Documentation” which works when the image cannot be displayed.
  • height: Here we pass the height parameter and set the height of an image to the value of 12 pixels.
  • width: Here we pass the width parameter and set the width of an image to the value of 4 pixels.

Step 8: Now, click on the “Check Syntax” button to verify whether the above-written formula is correct or not. If there is no error in the formula, you will get the message “No Syntax errors in merge fields or function”, otherwise you will get an error message.

Optionally, you can also define the “Description”, “Help Text” and “Handle the empty field” if you like and click on the “Next” button after that to move to the next step.

How to add image in the formula field in Salesforce

Step 9: In this step, setup the field-level security. Here, you have to choose the profiles which you want to allow field-level security editing access in order to customize the field-level security. If you have not chosen the profile, this particular field will be hidden from all the profiles.

For this example, I check the checkbox next to “Visible” as I want to give edit access of this field to all the profiles. Click on the “Next” button to move to the next step.

How to add image in the formula field in Salesforce Example

Step 10: In this step, you have to choose the page layout in which you want to will include the newly created custom formula field. After that, click on the “Save” button to finish the process of adding the image in the formula field.

Example of Salesforce IMAGE Function

You can use the formula field after you have created it. Let’s look at an example to show how it works:

  • Open the Contract Item and create a new contract and save it.
  • Once you save it, it moves to the Detail Section, where you will see the “Contract Documents” field with the link to an image. When you click on the link the contract document gets opened in the jpeg format.

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

Conclusion

In a nutshell, we have learned the Salesforce IMAGE function with the syntax and various real business-related examples. We have also learned that the usage of Salesforce IMAGE function is used to insert images in Salesforce.

Moreover, we have learned the step-by-step implementation of how to use the IMAGE function in Salesforce Lightning and Salesforce Classic to add the image in the Salesforce formula field.

You may like to read the following articles: